PictureBox - 给定坐标内的不透明度绘制

时间:2013-05-14 15:51:14

标签: vb.net paint picturebox

我有一个Picturebox,里面我想要绘制(不透明度,不完全隐藏绘制的区域)图片的确定区域与给定的协调。

到目前为止,我有'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

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

提前致谢。

1 个答案:

答案 0 :(得分:1)

尝试类似......

Highlighted Rectangle via Paint() Event

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