C# OpenFileDialog.ShowDialog 打不开,程序无响应

private Thread invokeThread;
private OpenFileDialog openFileDialog1;
private DialogResult result;

private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            string patch = "C:\\";
            openFileDialog1 = new OpenFileDialog();
            openFileDialog1.InitialDirectory = patch;
            openFileDialog1.Filter = "xls files(*.xls;*.xlsx)|*.xls;*.xlsx";

            invokeThread = new Thread(new ThreadStart(InvokeMethod));
            invokeThread.SetApartmentState(ApartmentState.STA);
            invokeThread.Start();
            invokeThread.Join();

            if (result == DialogResult.OK)
            {
                if (openFileDialog1.FileName != "")
                {
                    //获取到文件,进行处理
                }

            }
        }

private void InvokeMethod()
        {
            result = openFileDialog1.ShowDialog();
        }

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是几个VB.NET中 OpenFileDialog.ShowDialog 方法的实例代码和注释: 1. 基本用法: ``` Dim openFileDialog1 As New OpenFileDialog() openFileDialog1.Filter = "Text Files|*.txt" openFileDialog1.Title = "Select a Text File" If openFileDialog1.ShowDialog() = DialogResult.OK Then ' 用户选择了一个文件 End If ``` 2. 打开文件夹: ``` Dim folderBrowserDialog1 As New FolderBrowserDialog() If folderBrowserDialog1.ShowDialog() = DialogResult.OK Then ' 用户选择了一个文件夹 End If ``` 3. 多选文件: ``` Dim openFileDialog1 As New OpenFileDialog() openFileDialog1.Multiselect = True openFileDialog1.Filter = "Text Files|*.txt" openFileDialog1.Title = "Select Text Files" If openFileDialog1.ShowDialog() = DialogResult.OK Then ' 用户选择了一个或多个文件 For Each file As String In openFileDialog1.FileNames ' 处理每个文件 Next End If ``` 4. 指定初始目录: ``` Dim openFileDialog1 As New OpenFileDialog() openFileDialog1.InitialDirectory = "C:\Users\Public\Documents" openFileDialog1.Filter = "Text Files|*.txt" openFileDialog1.Title = "Select a Text File" If openFileDialog1.ShowDialog() = DialogResult.OK Then ' 用户选择了一个文件 End If ``` 5. 自定义按钮文本: ``` Dim openFileDialog1 As New OpenFileDialog() openFileDialog1.Filter = "Text Files|*.txt" openFileDialog1.Title = "Select a Text File" openFileDialog1.CustomPlaces.Add("C:\Users\Public\Documents") ' 自定义按钮文本 openFileDialog1.CustomPlaces.Add(New FileDialogCustomPlace("My Documents", "::{450D8FBA-AD25-11D0-98A8-0800361B1103}")) If openFileDialog1.ShowDialog() = DialogResult.OK Then ' 用户选择了一个文件 End If ``` 上述代码中的注释可以帮助您更好地理解 OpenFileDialog.ShowDialog 方法的使用。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值