1.2.3. Filter Filter属性可以过滤要选择的文件类型,也有两种方式,如下所示: 字符串格式的含义,|前面是文件打开格式的提示,|后面是显示该名称后缀的文件,如下所示: 1.2.4. Multiselect 此属性表示是否可以选择多个文件,默认是不可以多选的,代码如下所示: 1.2.5. 显示文本对话框 1.2.6. FileName 此属性返回选中...
一、OpenFileDialog 1、文件多个选择 openFileDialog.Multiselect=true; 2、多种文件类型选择 (1)多种文件类型可一起选择 eg1: openFileDialog.Filter = "(excel文件)|*.xls;*.xlsx"; eg2: openFileDialog.Filter = "图片文件(*.jpg,*.gif,*.bmp,*.png)|*.jpg;*.gif;*.bmp;*.png"; 类型描述(类型拓...
在这个示例中,我们创建了一个OpenFileDialog对象,设置了它的Multiselect、Title和Filter属性,然后调用了ShowDialog方法显示对话框。如果用户点击了“确定”按钮,我们就遍历FileNames属性中的每个文件路径,并打印出来。
我用来打开文本文件的代码: private void button1_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.InitialDirectory = @"C:\"; ofd.Filter = "TXT Files(*.txt;)|*.txt;"; if(ofd.ShowDialog() == DialogResult.OK) { using(StreamReader rdText = new StreamRea...
(); openFileDialog.Multiselect = true; // 启用多选功能 openFileDialog.Title = "选择多个文件"; openFileDialog.Filter = "所有文件|*.*"; if (openFileDialog.ShowDialog() == DialogResult.OK) { foreach (string filePath in openFileDialog.FileNames) { MessageBox.Show("选中的文件: " + filePath...
dialog=newOpenFileDialog();dialog.Multiselect=true;// 可以选择多个选项dialog.Title="选择图纸文件";dialog.RestoreDirectory=true;dialog.Filter="图纸文件(*.pdf; *.dxf)|*.pdf; *.dxf";DialogResultdialogRes=dialog.ShowDialog();if(dialogRes==DialogResult.OK){vardrawingsNode=this.componentTreeView.Nodes....
OpenFileDialog组件的Multiselect属性//是否允许多选 public bool Multiselect {get;ser;} FileNames属性 //获取所有选定的文件的文件名 public string[] FileName {get;} 实现代码: privatevoidbutton1_Click(objectsender,EventArgse){openFileDialog1.Filter="txt文件(*.txt)|*.txt";openFileDialog1.Multiselect=tr...
1.OpenFileDialog 中文名字叫做 打开文件对话框 OpenFileDialog的效果如图: 1 private void btnSelectFile_Click(object sender, EventArgs e) 2 { 3 openFileDialog1.InitialDirectory = "c:\\";//默认路径,注意这里写路径时要用c:\\而不是c:\ 4 openFileDialog1.Filter = "XML文件|*.xml";//过滤的文件,...
= "C:\\";//设置打开时的默认路径,我这里设置为C盘根目录string filter = "txt,doc";filter = filter.TrimEnd(',');if (filter.Equals("")){ filter = "*";}filter = filter.Replace(",", ";*.");filter = "*." + filter;openFile.Filter = "Txt files ("...
public bool Multiselect {get;ser;} FileNames属性 //获取所有选定的文件的文件名 public string[] FileName {get;} 实现代码: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 privatevoidbutton1_Click(objectsender, EventArgs e) { openFileDialog1.Filter ="txt文件(*.txt)|*.txt"; ...