Circular Hitbox in Visual Basic WinForm

Advertisements

How can I change the hitbox of a PictureBox where the image is circular? By hitbox, I mean where the ClickEvent registers.

>Solution :

You can use the Control.Region property, to create a Region using a circular GraphicsPath. This Region is used for the Click event, as well as the MouseEnter, MouseHover, and MouseLeave events.

Example with a PictureBox:

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim path As New Drawing2D.GraphicsPath()
        path.AddArc(0, 0, PictureBox1.Width, PictureBox1.Height, 0, 360) 'A circle at 0,0 relative to the PictureBox, sharing its Width and Height
        PictureBox1.Region = New Region(path)
End Sub

Leave a ReplyCancel reply