0

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

 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 错误。

我试图在导致上述错误的“句柄”之后添加按钮单击事件。

 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 个这样的。

4

1 回答 1

0

你可以试试

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    imgLabel_Click(imgLabel, nothing)
End Sub
于 2017-10-29T21:07:30.180 回答