OpenFileDialogue打开两次 [英] OpenFileDialogue opens twice

查看:230
本文介绍了OpenFileDialogue打开两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有此代码:

    Private Sub btnChangeDirCfg_Click(sender As Object, e As EventArgs) Handles btnChangeDirCfg.Click
        Dim CfgDialogue As New OpenFileDialog()                                     'Using the new Dialogue box;
        CfgDialogue.Filter = "Configuration Files (*.BLK)|*.BLK"                    '[1/2] Set Dialogue params
        CfgDialogue.ShowDialog()                                                    '[2/2] Show the dialogue box

        If (CfgDialogue.ShowDialog() = System.Windows.Forms.DialogResult.OK) Then
            CfgFile = CfgDialogue.FileName                                           'Store Filename as Var
            txtShowVarCfg.Text = (CfgFile)                                           'Using Var, present the files location
            My.Settings.SavedConfig = (CfgFile)                                      'Save config file location to config
        End If
    End Sub

Public CfgFile As String = String.Empty

我无法弄清楚问题的原因.

I can't figure out the cause of the problem I have.

当我按下按钮时,对话框及其过滤器会正确弹出.我选择名为"config.blk"的文件.单击打开"按钮(传递为确定")后,将打开一个新的副本对话框,但文件名已作为从中选择的目录填充 上一个对话框.文本字段也仅在第二对话框关闭后才填写:(

When I hit the button, the Dialog pops up correctly with its filter. I choose the file named "config.blk". After I click the Open button (passed as OK), a new replica dialog box opens but the filename is already filled in as the selected dir from the previous dialog box. The text field is only filled in after the 2nd dialog box has been closed too :(

我不知道为什么会这样.希望有人能提供帮助:)

I've no idea why this is happening. I hope someone can help :)

推荐答案

没关系,我通过删除" CfgDialogue ()"行.

Nevermind, I fixed it by removing the "CfgDialogue.ShowDialog()" line.

谢谢:)


这篇关于OpenFileDialogue打开两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆