views:

254

answers:

3

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

alt text

+1  A: 

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.

James Westgate
+1  A: 

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))

...

Paul Sasik
I think a rectangle and a polygon will work, i'll give it a shot.
Kevin
@Kevin: added some sample drawing code to expand on what i was imagining. Do note that it is hard-coded and does not bother outlining the inner triangle. Not enough time today. ;-)
Paul Sasik
@Paul: the inside borders are a bit more tricky.
Kevin
A: 

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

Mads