[英]How do I convert picturebox.click event into a button.click event
I'm trying to have two options to draw a border around a picture box. 我试图有两个选择在图片框周围绘制边框。 I can click on the picturebox to highlight but now would like to be able to use a button to do the same thing.
我可以单击图片框以突出显示,但现在希望能够使用按钮来执行相同的操作。
Private Sub imgLabel_Click(sender As Object, e As EventArgs) Handles imgLabel.Click
Dim BorderBounds As Rectangle = DirectCast(sender, PictureBox).ClientRectangle BorderBounds.Inflate(-1, -1)
ControlPaint.DrawBorder(DirectCast(sender, PictureBox).CreateGraphics, BorderBounds, Color.Orange, ButtonBorderStyle.Solid)
If Not (HighLightededPictureBox Is Nothing) Then
HighLightededPictureBox.Invalidate()
End If
'Rememeber the last highlighted PictureBox
HighLightededPictureBox = CType(sender, PictureBox)
When I try to add a button click I get the Exception Unhandled - System.windows.forms.button to type System.windows.forms.picturebox error. 当我尝试添加按钮时,单击“出现未处理的异常-System.windows.forms.button”,键入System.windows.forms.picturebox错误。
I have tried to add the button click event after "Handles" which causes the above error. 我试图在导致上述错误的“句柄”之后添加按钮单击事件。
Private Sub imgLabel_Click(sender As Object, e As EventArgs) Handles imgLabel.Click, button1.click
I'm pretty new to programming and my searching results are turning anything up of value. 我对编程还很陌生,我的搜索结果正在使任何东西变得有价值。 I don't fully understand Ctypes/Directcasts.
我不太了解Ctypes / Directcast。
Any help is greatly appreciated. 任何帮助是极大的赞赏。
Ok, so I ended up going with this... 好的,所以我最终选择了这个...
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim boxsize As New Size(192, 169)
Dim recpoint As New Point(0, 0)
Dim myrectangle As New Rectangle(recpoint, boxsize)
myrectangle.Inflate(-3, -3)
Dim G As Drawing.Graphics = PictureBox1.CreateGraphics
Dim Pen As New Pen(Color.Orange, 5)
G.DrawRectangle(Pen, myrectangle)
End Sub
Seems to be working ok, but requires a lot of manual entry of points. 似乎可以正常运行,但需要大量手动输入点。 I have 6 more of these.
我还有六个。
You could try 你可以试试
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
imgLabel_Click(imgLabel, nothing)
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.