OpenFileDialog用于文件选择

OpenFileDialog用于文件选择

本文介绍了OpenFileDialog用于文件选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我有一个带文件名的字段,我希望当我点击该字段时,文件选择窗口(资源管理器)会被打开然后选择所需的文件(必须是xls或xlsx文件)。



但是当我点击该字段时,它会打开进行编辑,没有别的。

,我有以下说明:

  this  .bomNameFld.Click + =  new  System.EventHandler( this  .bomNameFld_Click); 





和方法,使用以下代码

 private void bomNameFld_Click(object sender,EventArgs e)
{
OpenFileDialog openFile = new OpenFileDialog();
string file = openFile.FileName;
bomNameFld.Text = file;
}





我也试过使用Mouseclick和MouseEventhandler,结果是一样的。



任何人都可以帮助我吗?



提前谢谢。



David。

解决方案



Hello,

I have a field with a file name, and I want that when I click on that field, the file selection window (explorer) gets opened and thus select the desired file (must be an xls or xlsx file).

But when I click on the field, it opens for edit, nothing else.

in the design file, I have the following instruction:

this.bomNameFld.Click += new System.EventHandler(this.bomNameFld_Click);



and the method, with the following code

private void bomNameFld_Click(object sender, EventArgs e)
{
    OpenFileDialog openFile = new OpenFileDialog();
    string file = openFile.FileName;
    bomNameFld.Text = file;
}



I have also tryed using Mouseclick and MouseEventhandler, but the result is the same.

Can anyone help me?

Thank you in advance.

David.

解决方案



这篇关于OpenFileDialog用于文件选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 07:58