如何将picturebox.click事件转换为button.click事件

时间:2017-10-27 17:10:46

标签: vb.net drawing directcast

我正在尝试使用两个选项在图片框周围绘制边框。 我可以点击图片框突出显示,但现在希望能够使用按钮来做同样的事情。

 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)

当我尝试添加按钮时,我得到Exception Unhandled - System.windows.forms.button以输入System.windows.forms.picturebox错误。

我试图在“Handles”之后添加按钮点击事件,这会导致上述错误。

 Private Sub imgLabel_Click(sender As Object, e As EventArgs) Handles imgLabel.Click, button1.click

我对编程很陌生,我的搜索结果正在变得有价值。我不完全了解Ctypes / Directcasts。

非常感谢任何帮助。

好的,所以我最终选择了......

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

似乎工作正常,但需要大量手动输入点数。我还有6个。

1 个答案:

答案 0 :(得分:0)

你可以尝试

Schema::rename('foo', 'bar');