PictureBox 的图像不会出现在新表单中,该表单应在停用时关闭
PictureEdit 或 PictureBox 的图像未在新表单 (Form2
) 中显示。
此外,当单击父窗体(form1)中的不同控件时,这个新窗体应该自动关闭。
使用我的代码,当我双击 Form1 中的图像时,仅出现第三个图像。
有没有办法让我不需要根据Form1中的图像数量创建3个新表单?
作为记录,我使用 Visual Studio 2010
Public Class Form1
Private Sub PictureEdit1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureEdit1.DoubleClick
Dim yourForm As New Form2()
yourForm.ShowDialog()
End Sub
Private Sub PictureEdit2_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureEdit2.DoubleClick
Dim yourForm As New Form2()
yourForm.ShowDialog()
End Sub
Private Sub PictureEdit3_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureEdit3.DoubleClick
Dim yourForm As New Form2()
yourForm.ShowDialog()
End Sub
End Class
Public Class Form2
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Form_One As Form1 = CType(Application.OpenForms("form1"), Form1)
Me.PictureEdit1.Image = Form_One.PictureEdit1.Image
Me.PictureEdit1.Image = Form_One.PictureEdit2.Image
Me.PictureEdit1.Image = Form_One.PictureEdit3.Image
End Sub
End Class
The Image of a PictureEdit or PictureBox is not shown in a new form (Form2
).
Also, this new Form should auto-close when clicking on a different Control in the parent form (form1).
With my code, only the third Image appears when I double-click on an Image in Form1.
Is there a solution so that I do not need to create 3 new forms according to the number of images in Form1?.
For the record, I use Visual Studio 2010
Public Class Form1
Private Sub PictureEdit1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureEdit1.DoubleClick
Dim yourForm As New Form2()
yourForm.ShowDialog()
End Sub
Private Sub PictureEdit2_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureEdit2.DoubleClick
Dim yourForm As New Form2()
yourForm.ShowDialog()
End Sub
Private Sub PictureEdit3_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureEdit3.DoubleClick
Dim yourForm As New Form2()
yourForm.ShowDialog()
End Sub
End Class
Public Class Form2
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Form_One As Form1 = CType(Application.OpenForms("form1"), Form1)
Me.PictureEdit1.Image = Form_One.PictureEdit1.Image
Me.PictureEdit1.Image = Form_One.PictureEdit2.Image
Me.PictureEdit1.Image = Form_One.PictureEdit3.Image
End Sub
End Class
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
所需的小更改:
OnDeactivate
,以便在您单击表单外部时关闭表单。Show(Me)
而不是ShowDialog()
:这将使调用 Form 成为 Form2 的所有者,因此它位于其所有者之上,但它不是模态窗口,当您在窗口外部单击时,该窗口不会被停用。Small changes required:
OnDeactivate
, to close the Form when you click outside of it.Show(Me)
instead ofShowDialog()
: this will make the calling Form the Owner of Form2, so it stays on top of its owner, but it's not a Modal Window, which is not deactivated when you click outside of it.完成 Jimi 建议的更改后,您还可以通过在“Handles”关键字后列出多个控件/事件,使用 ONE sub 来处理所有三个 PictureEdit 控件:
Once you've made the changes suggested by Jimi, you can also use ONE sub to handle all three PictureEdit controls by listing more than one control/event after the "Handles" keyword: