Question

What GDI methods can I use to draw the blue shape shown in the image below? The center must be transparent.

alt text

Was it helpful?

Solution

There are a number of ways but you'll probably want to use the following:

FillRectangle
FillPolygon
DrawLine

since it looks like your shape can be reduced to a rectangle and two polygons and then outlined by a few lines.

Here is a really simple and hard-coded example of what i was thinking:

Private Sub Control_Paint(ByVal sender As Object, ByVal e As PaintEventArgs) _
Handles MyBase.Paint
    Dim g As Graphics = e.Graphics

    g.FillRectangle(Brushes.Aqua, New Rectangle(10, 10, 10, 90))
    g.FillPolygon(Brushes.Aqua, New Point() { _
        New Point(10, 10), _
        New Point(20, 10), _
        New Point(40, 50), _
        New Point(30, 50)})
    g.FillPolygon(Brushes.Aqua, New Point() { _
        New Point(10, 100), _
        New Point(20, 100), _
        New Point(40, 50), _
        New Point(30, 50)})
    g.DrawLine(Pens.Black, New Point(10, 10), New Point(10, 100))
    g.DrawLine(Pens.Black, New Point(10, 100), New Point(20, 100))
    g.DrawLine(Pens.Black, New Point(20, 100), New Point(40, 50))
    g.DrawLine(Pens.Black, New Point(40, 50), New Point(20, 10))
    g.DrawLine(Pens.Black, New Point(20, 10), New Point(10, 10))

...

OTHER TIPS

Im assuming GDI+ here aka System.Drawing namespace.

The best thing to do is to look at System.Drawing.Drawing2d.GraphicsPath class :

http://msdn.microsoft.com/en-us/library/system.drawing.drawing2d.graphicspath.aspx

You need to make sure you close the path to get the hollow effect.

Wouldn't it just be easier to draw it using a bitmap? That's what they're for anyway :).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top