5,401,186 members and growing! (18,647 online)
Email Password   helpLost your password?
Multimedia » GDI+ » General     Intermediate

Shapes and Regions

By Guerven

Using Graphics.DrawPolygon and Region to add irregular buttons to your form.
C#, VB.NET 1.1, Win2K, WinXP, Windows, .NETVisual Studio, VS.NET2003, Dev

Posted: 26 Sep 2005
Updated: 26 Sep 2005
Views: 28,139
Bookmarked: 7 times
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
7 votes for this Article.
Popularity: 2.87 Rating: 3.40 out of 5
3 votes, 42.9%
1
0 votes, 0.0%
2
0 votes, 0.0%
3
1 vote, 14.3%
4
3 votes, 42.9%
5

Sample Image

Introduction

It is often a good idea to add irregular buttons to an application. This may be achieved by combining the use of Graphics.DrawPolygon and Region.

Background

I needed to plot city boundaries using VB.NET and I needed to make the plot interactive. The users would click on a city and the application should display information about that city. This led me to use Graphics.DrawPolygon to display the boundaries and apply a Region to make the shapes clickable.

Using the code

There are two forms in the project. Form1 contains the code below, the shape editor on the other hand can be used to generate x:y coordinates of a shape. One can draw the shape in the picture box and copy the points in the listbox.

Private Sub Button1_Click(ByVal sender As System.Object, _
              ByVal e As System.EventArgs) Handles Button1.Click
    Dim H(3) As Point
    Dim J As New Kring()

    ' make a square polygon

    H(0) = New Point(100, 100)
    H(1) = New Point(300, 100)
    H(2) = New Point(300, 400)
    H(3) = New Point(100, 400)
    'you can create a complex set of points

    J.KKline = H

    ' I don't know how to set the fillbrush during design time so just 

    '  specify other attributes via code

    J.FillBrush = New SolidBrush(Color.Blue)

    ' it is important that the objects size be equal to

    ' the canvas or this in this case the form.

    ' the canvas may also be a picturebox or other windows control

    ' example :

    ' Picturebox1.controls.add(J)

    ' j.size = picturebox1.size


    J.Size = Me.Size
    Me.Controls.Add(J)
End Sub

Points of Interest

I'm looking at developing a much faster and effective way to display clickable shapes. I've already used the same method (just applied geodetic formulas) to plot building footprints, road networks, and parcel vectors. But I cannot share those codes because they're my company properties.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Guerven









Occupation: Web Developer
Location: Philippines Philippines

Other popular GDI+ articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 2 of 2 (Total in Forum: 2) (Refresh)FirstPrevNext
Subject  Author Date 
GeneralDemo and source filesmembercolinmc9:26 5 Oct '05  
GeneralRe: Demo and source filesmemberGuerven20:17 10 Oct '05  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 26 Sep 2005
Editor: Smitha Vijayan
Copyright 2005 by Guerven
Everything else Copyright © CodeProject, 1999-2008
Web10 | Advertise on the Code Project