繁体   English   中英

为什么当我处理表单并再次返回时 openFileDialog 没有响应?

[英]Why openFileDialog doesn't responding when i dispose the form and back to it again?

我有一个表单中的两个openFileDialog工具,当我浏览openFileDialog1并选择一张图片时,可以,但是当我处理此表单并返回它并单击以浏览另一张图片时,它没有响应并且项目停止并且没有错误! !!

    Private Sub Browse_Click(sender As Object, e As EventArgs) Handles Browse.Click
        OpenFileDialog1.FileName = ""
        OpenFileDialog1.Filter = "Image Files (*.jpg, *.bmp, *.gif, *.png)|*.jpg; *.bmp; *.gif; *.png"
        If OpenFileDialog1.FileName = "" Then
            If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
                txtFileName.Text = OpenFileDialog1.FileName
                txtFileName.SelectionStart = txtFileName.Text.Length 'to show the last portion of text
                If Trim(txtFileName.Text) <> "" Then picSave.Image = Image.FromFile(txtFileName.Text)
            End If
        Else
            Exit Sub
        End If
    End Sub

    Private Sub Btnclose_Click(sender As Object, e As EventArgs) Handles Btnclose.Click
        Me.Dispose()
    End Sub

在 Project Properties 中,确保您已将 Shutdown Mode 设置为“When last form closes”。 这不是默认设置。

在此处输入图片说明

在 Form1 中

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    OpenFileDialog1.Filter = "Image Files (*.jpg, *.bmp, *.gif, *.png)|*.jpg; *.bmp; *.gif; *.png"
    If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
        TextBox1.Text = OpenFileDialog1.FileName
        PictureBox1.Image = Image.FromFile(TextBox1.Text)
    End If
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Form2.Show()
    Close()
End Sub

然后在 Form2 中

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Form1.Show()
    Close()
End Sub

当我返回 Form1 时,OpenFileDialog 行为正常。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM