OpenFileDialog dlgOpenFile = new OpenFileDialog(); dlgOpenFile.ShowReadOnly = true; if(dlgOpenFile.ShowDialog() == DialogResult.OK) { // If ReadOnlyChecked is true, uses the OpenFile method to // open the file with read/only access. string path = null; try { if(dlgOpenFile.ReadOnly...
OpenFileDialog openFileDlg =newOpenFileDialog(); openFileDlg.Title="选择文件"; openFileDlg.Multiselect=false; openFileDlg.InitialDirectory=Environment.GetFolderPath(Environment.SpecialFolder.Desktop);//设置默认路径为桌面 openFileDlg.Filter="(*.jpg,*.png,*.jpeg,*.bmp,*.gif)|*.jgp;*.png;*.jpeg;...
可以用以下代码来实现上面这个对话框: private void openFileDialogBTN_Click(object sender, System.EventArgs e){ OpenFileDialog openFileDialog=new OpenFileDialog(); openFileDialog.InitialDirectory="c:\\";//注意这里写路径时要用c:\\而不是c:\ openFileDialog.Filter="文本文件|*.*|C#文件|*.cs|所有文件...
//打开文件private void button3_Click(object sender, EventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); if (dlg.ShowDialog() == DialogResult.OK) MessageBox.Show(dlg.FileName); }
OpenFileDialog dlgOpenFile = new OpenFileDialog(); dlgOpenFile.ShowReadOnly = true; if(dlgOpenFile.ShowDialog() == DialogResult.OK) { // If ReadOnlyChecked is true, uses the OpenFile method to // open the file with read/only access. string path = null; try { if(dlgOpenFile.ReadOnly...
OpenFileDialog dlgOpenFile = new OpenFileDialog(); dlgOpenFile.ShowReadOnly = true; if(dlgOpenFile.ShowDialog() == DialogResult.OK) { // If ReadOnlyChecked is true, uses the OpenFile method to // open the file with read/only access. string path = null; try { if(dlgOpenFile.ReadOnly...
OpenFileDialogdlg=newOpenFileDialog(); dlg.Title="选择要转换的图片"; dlg.Filter="Image files (*.jpg;*.bmp;*.gif;*.png)|*.jpg;*.jpeg;*.gif;*.bmp;*.png|AllFiles (*.*)|*.*"; if (DialogResult.OK== dlg.ShowDialog()) {
if (dlg.ShowDialog() == DialogResult.OK) MessageBox.Show(dlg.SelectedPath.ToString()); } //打开文件 private void button3_Click(object sender, EventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); if (dlg.ShowDialog() == DialogResult.OK) ...
OpenFileDialog ofdg = new OpenFileDialog();if (ofdg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK){ string file = ofdg.FileName;//得到选择的文件的完整路径 textBox1.Text = System.IO.File.ReadAllText(file, Encoding.Default);//把读出来的数据显示在textbox中 } } 注意...
使用OpenFileDialog.ShowDialog()方法弹出一个模式对话框,保证打开窗口总是获取该程序的当前焦点,这样你就没办法再次点击那个按钮了