frm.showDialog 当 openFileDialog 关闭时处理 [vb.net]
frm.showDialog dispose when openFileDialog close [vb.net]
我有两种形式。第一种形式用于显示一组记录,第二种形式用于编辑特定记录。我使用 frm.ShowDialog() 调用了第二种形式。在该窗体中,我有一个调用 OpenFileDialog 的按钮。当我按确定或取消时,第二个表单将与 OpenFileDialog 一起处理。我很高兴我的代码是正确的,但这是 ShowDialog() 问题。有人对这个问题有想法吗?
这就是我从第一个表单调用第二个表单来显示信息的方式。
Private Sub btnViewOrganizationEdit_Click(sender As Object, e As EventArgs) Handles btnViewOrganizationEdit.Click, dgvOrganization.DoubleClick
Dim selectedOrganization As New Organization
'check permission because double click
If dgvOrganization.RowCount > 0 Then
strOrganizationID = dgvOrganization.SelectedRows.Item(0).Cells(0).Value
selectedOrganization = helperOrganizationCKJ.getOrganizationByID(strOrganizationID)
frmEditOrganizationCKJ.objOrganization = selectedOrganization
frmEditOrganizationCKJ.ShowDialog()
iniGridView()
End If
End Sub
这就是我调用 OpenFileDialog 的方式。
Private Sub btnEditOrganizationImage_Click(sender As Object, e As EventArgs) Handles btnEditOrganizationImage.Click
dlgImage.Filter = ""
Dim codecs() As ImageCodecInfo = ImageCodecInfo.GetImageEncoders()
Dim sep As String = String.Empty
For Each c As ImageCodecInfo In codecs
Dim codecName As String = c.CodecName.Substring(8).Replace("Codec", "Files").Trim()
dlgImage.Filter = String.Format("{0}{1}{2} ({3})|{3}", dlgImage.Filter, sep, codecName, c.FilenameExtension)
sep = "|"
Next
dlgImage.FilterIndex = 5
If dlgImage.ShowDialog(Me) = DialogResult.OK Then
'Get the image name
Dim img = dlgImage.FileName
picEditOrganizationImage.Image = System.Drawing.Bitmap.FromFile(img)
End If
End Sub
frmEditOrganizationCKJ 只是和 OpenFileDialog 一起处理。
可能您 copy/pasted 您的 btnEditOrganizationImage 按钮的 DialogResult 属性 设置与 [=25= 不同].
这会触发模态表单的关闭操作,修复非常简单。
将 btnEditOrganizationImage 的 属性 DialogResult 设置为 DialogResult.None
来自 Button.DialogResult
上的 MSDN
If the DialogResult for this property is set to anything other than
None, and if the parent form was displayed through the ShowDialog
method, clicking the button closes the parent form without your having
to hook up any events. The form's DialogResult property is then set to
the DialogResult of the button when the button is clicked
我有两种形式。第一种形式用于显示一组记录,第二种形式用于编辑特定记录。我使用 frm.ShowDialog() 调用了第二种形式。在该窗体中,我有一个调用 OpenFileDialog 的按钮。当我按确定或取消时,第二个表单将与 OpenFileDialog 一起处理。我很高兴我的代码是正确的,但这是 ShowDialog() 问题。有人对这个问题有想法吗?
这就是我从第一个表单调用第二个表单来显示信息的方式。
Private Sub btnViewOrganizationEdit_Click(sender As Object, e As EventArgs) Handles btnViewOrganizationEdit.Click, dgvOrganization.DoubleClick
Dim selectedOrganization As New Organization
'check permission because double click
If dgvOrganization.RowCount > 0 Then
strOrganizationID = dgvOrganization.SelectedRows.Item(0).Cells(0).Value
selectedOrganization = helperOrganizationCKJ.getOrganizationByID(strOrganizationID)
frmEditOrganizationCKJ.objOrganization = selectedOrganization
frmEditOrganizationCKJ.ShowDialog()
iniGridView()
End If
End Sub
这就是我调用 OpenFileDialog 的方式。
Private Sub btnEditOrganizationImage_Click(sender As Object, e As EventArgs) Handles btnEditOrganizationImage.Click
dlgImage.Filter = ""
Dim codecs() As ImageCodecInfo = ImageCodecInfo.GetImageEncoders()
Dim sep As String = String.Empty
For Each c As ImageCodecInfo In codecs
Dim codecName As String = c.CodecName.Substring(8).Replace("Codec", "Files").Trim()
dlgImage.Filter = String.Format("{0}{1}{2} ({3})|{3}", dlgImage.Filter, sep, codecName, c.FilenameExtension)
sep = "|"
Next
dlgImage.FilterIndex = 5
If dlgImage.ShowDialog(Me) = DialogResult.OK Then
'Get the image name
Dim img = dlgImage.FileName
picEditOrganizationImage.Image = System.Drawing.Bitmap.FromFile(img)
End If
End Sub
frmEditOrganizationCKJ 只是和 OpenFileDialog 一起处理。
可能您 copy/pasted 您的 btnEditOrganizationImage 按钮的 DialogResult 属性 设置与 [=25= 不同].
这会触发模态表单的关闭操作,修复非常简单。
将 btnEditOrganizationImage 的 属性 DialogResult 设置为 DialogResult.None
来自 Button.DialogResult
上的 MSDNIf the DialogResult for this property is set to anything other than None, and if the parent form was displayed through the ShowDialog method, clicking the button closes the parent form without your having to hook up any events. The form's DialogResult property is then set to the DialogResult of the button when the button is clicked