如何创建一个button控件,进行资源选择

创建一个button控件,点击时会自动查询本机文件,点击文件会自动把文件路径加载到TextBox控件里。4

  首先需要添加一个空间openFileDialog

    private void button1_Click(object sender, EventArgs e)
{
this.openFileDialog1.ShowDialog();
//选择文件后,用openFileDialog1的FileName属性获取文件的绝对路径
this.label1.Text = this.openFileDialog1.FileName;
}
 

原文地址:https://www.cnblogs.com/zhaoguoying/p/9405229.html