What GDI methods can I use to draw the blue shape shown in the image below? The center must be transparent.
Asked
Active
Viewed 830 times
3 Answers
1
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
- 79,492
- 20
- 149
- 189
-
I think a rectangle and a polygon will work, i'll give it a shot. – Kevin Mar 30 '10 at 21:50
-
@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 Mar 30 '10 at 22:28
0
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
- 11,306
- 8
- 61
- 68