OpenFileDialog方法的编辑
使用此类可检查某个文件是否存在并打开该文件。
ShowReadOnly 属性确定是否在对话框中显示只读复选框。
ReadOnlyChecked 属性指示是否选中只读复选框。
此类的大多数功能都可以在 FileDialog 类中找到。
如果要使用户能够选择文件夹而不是文件,
此类的大多数功能都可以在 FileDialog 类中找到。
如果要使用户能够选择文件夹而不是文件,
请改用 FolderBrowserDialog。
实例:
private void button1_Click(object sender, System.EventArgs e)
{
Stream myStream;
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "c:\\" ;
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*" ;
openFileDialog1.FilterIndex = 2 ;
openFileDialog1.RestoreDirectory = true ;
if(openFileDialog1.ShowDialog() == DialogResult.OK)
{
if((myStream = openFileDialog1.OpenFile())!= null)
{
// Insert code to read the stream here.
myStream.Close();
}
}
}
实例:
private void button1_Click(object sender, System.EventArgs e)
{
Stream myStream;
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "c:\\" ;
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*" ;
openFileDialog1.FilterIndex = 2 ;
openFileDialog1.RestoreDirectory = true ;
if(openFileDialog1.ShowDialog() == DialogResult.OK)
{
if((myStream = openFileDialog1.OpenFile())!= null)
{
// Insert code to read the stream here.
myStream.Close();
}
}
}
文章题目:OpenFileDialog方法的编辑
转载源于:http://myzitong.com/article/jgpieg.html