hello friends,
how can i design a region in vb.net form(windows application), such that when i click any point inside a region a new page opens.
my problem is that the region which i want to define through it is very complex..its a combination of a rectangle and another shape.
thanks for your help:)

Dani AI

Generated

Short summary: the GraphicsPath/Region approach that described is the right foundation for arbitrary, non‑rectangular click regions. Two distinct patterns are useful depending on intent: either assign a Region to the form/control to actually reshape the window (affects hit testing and window chrome), or keep the UI rectangular and perform hit testing against a prebuilt GraphicsPath/Region to open a new page when a click lies inside the shape.

Practical workflow (no code shown here): represent the shape as a point list or as curves, build a GraphicsPath with the appropriate FillMode (winding vs even‑odd for holes), then flatten/simplify curves to reduce vertex count for performance. For image‑derived shapes, convert the alpha mask to a contour (marching‑squares/contour trace) and polygonize the boundary rather than testing every pixel. Store coordinates normalized to ClientSize and rebuild the path on Resize or DPI changes.

Hit testing and UX tips: use a quick bounding‑rectangle Contains test to reject most mouse events before calling the heavier IsVisible/Region.IsVisible check; cache the Region/GraphicsPath and only recreate when geometry or size changes; update the cursor on MouseMove (hit => hand cursor) and perform the open‑page action on MouseClick. To make clicking forgiving, test a small neighborhood around the pointer instead of a single pixel.

Pitfalls and cautions: setting Form.Region actually trims the clickable area of the window and can affect shadows/drag behavior—use it only when reshaping the window is intended. Coordinate transforms applied at draw time must also be applied to the path used for hit tests, or test points must be transformed the same way. For very complex outlines, simplify contours (Douglas‑Peucker) or break the region into subregions and combine them with Region.Combine for cleaner logic.

Recommended Answers

All 6 Replies

Member Avatar for Member #857553

Create the region with a GraphicsPath

Dim GraphicsPath As New Drawing2D.GraphicsPath(Drawing2D.FillMode.Winding)
   GraphicsPath.AddRectangle(New Rectangle(10, 10, 110, 110))
   GraphicsPath.AddEllipse(New Rectangle(50, 50, 100, 100))

   Me.Region = New Region(GraphicsPath)
Member Avatar for Member #857553

I may have read your post wrong.

This might be more of what your looking for.

Public Class Form1

    Private GraphicsPath As Drawing2D.GraphicsPath

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        GraphicsPath = New Drawing2D.GraphicsPath(Drawing2D.FillMode.Winding)
        GraphicsPath.AddRectangle(New Rectangle(10, 10, 110, 110))
        GraphicsPath.AddEllipse(New Rectangle(50, 50, 100, 100))

    End Sub

    Private Sub Form1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick
        If GraphicsPath.IsVisible(e.X, e.Y) Then
            MsgBox("Open a form")
        End If
    End Sub

    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        e.Graphics.DrawPath(Pens.Black, GraphicsPath)
    End Sub

End Class

thanx for the post...
what if i wanted a unique region and not these predefined regions.

Member Avatar for Member #857553

The GraphicsPath has 14 Add methods. You say you want to create a region that is made up of a rectangle and another shape. What is the other Shape?

------------------------|
|
|
|-------------------------------------------------------
|
|
|
|
--------------------------------------------------------------------------------

Member Avatar for Member #857553

Not exactly sure what that is. If that is supposed to be a solid area then you can create a polygon by defining the points.

Top Left Corner 0,0
Top Right Corner 50,0
Middle Right Corner 100,25
Bottom Right Corner 125,100
Bottom Left Corner 0,100

Put those points into a Point array and use the AddPolygon method of the Graphics Path.

So Something Like:

Dim CustomPolygon(4) as Point

CustomPolygon(0) = new point(0,0)
CustomPolygon(1) = new point(50,0)
.......

GraphicsPath.AddPolygon(CustomPolygon)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.