0

我有一个图片框,我想在里面绘制(不透明度不完全隐藏绘制区域)图片的确定区域,并给出坐标。

到目前为止,当用户单击图片框时,我已经有了“IF”语句,它会检查是否是具有正确坐标的区域:

If LocalMousePosition.X >= 87 And LocalMousePosition.X <= 131 And LocalMousePosition.Y >= 5 And LocalMousePosition.Y <= 55 Then

            Label1.Text = "coordinate correct"
        Else
            Label1.Text = ""

End If

现在我不知道如何绘制点击区域。

提前致谢。

4

1 回答 1

1

尝试类似...

通过 Paint() 事件突出显示的矩形

Public Class Form1

    Private InTarget As Boolean = False
    Private Target As New Rectangle(New Point(87, 5), New Size(45, 51))

    Private Sub PictureBox1_Click(sender As System.Object, e As System.EventArgs) Handles PictureBox1.Click
        Dim clientCoords As Point = PictureBox1.PointToClient(Cursor.Position)
        InTarget = Target.Contains(clientCoords)
        Label1.Text = IIf(InTarget, "coordinate correct", "")
        PictureBox1.Refresh()
    End Sub

    Private Sub PictureBox1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
        If InTarget Then
            Using highlight As New SolidBrush(Color.FromArgb(128, Color.Yellow)) ' 0 to 255
                e.Graphics.FillRectangle(highlight, Target)
            End Using
        End If
    End Sub

End Class
于 2013-05-14T16:27:52.197 回答