Drawing a wheel

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to draw a wheel. It should look about like the Wheel of Fortune wheel. I also need to be able to change the colors in each section. I know how to draw circles and lines but I have no idea how to fill each section with different colors. Can someone post a little sample code. Perhaps a circle in 2 pieces that you can change the color?
 
Eric,

You will want to use the FillRegion method on the Graphics class to fill
the region of the "wheel" that you are painting. Basically, the region will
consist of the rounded part of the slice, as well as the sides. You will
want to use an instance of the GraphicsPath class to create a path that
defines the region.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Eric said:
I need to draw a wheel. It should look about like the Wheel of Fortune
wheel. I also need to be able to change the colors in each section. I know
how to draw circles and lines but I have no idea how to fill each section
with different colors. Can someone post a little sample code. Perhaps a
circle in 2 pieces that you can change the color?
 
DrawArc() and FillRegion() methods inside System.Drawing
namespace are the methods you might prabably be looking
for.... but I'm sorry I don't have any sample code with
me...

HTH
Sunil
-----Original Message-----
I need to draw a wheel. It should look about like the
Wheel of Fortune wheel. I also need to be able to change
the colors in each section. I know how to draw circles
and lines but I have no idea how to fill each section with
different colors. Can someone post a little sample code.
Perhaps a circle in 2 pieces that you can change the color?
 
I see how fillRegion() works but I don't see how to adapt it to the parts of the circle. They are pie shaped.
 
Eric,

You will have to define the region, using lines and arcs to declare your
"slices" of the pie. You can use the GraphicsPath class to do this, and
then get a region from that.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Eric said:
I see how fillRegion() works but I don't see how to adapt it to the parts
of the circle. They are pie shaped.
 
Eric said:
I need to draw a wheel. It should look about like the Wheel of Fortune
wheel. I also need to be able to change the colors in each section. I know
how to draw circles and lines but I have no idea how to fill each section
with different colors. Can someone post a little sample code. Perhaps a
circle in 2 pieces that you can change the color?


System.Graphics.Games.WheelOfFortune.Wheel();

(Just kidding!)
 
Something like this perhaps?

Random r=new Random(DateTime.Now.Millisecond);

private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs
e)

{

e.Graphics.FillEllipse(Brushes.BlanchedAlmond,0,0,this.ClientSize.Width,this
..ClientSize.Height);

for(double a=0; a<360; a+=30)

{

SolidBrush b=new SolidBrush(Color.FromArgb(r.Next(255),
r.Next(255),r.Next(255)));

e.Graphics.FillPie(b,10,10,this.ClientSize.Width-20,this.ClientSize.Height-2
0,(float)a,25);

}

}


--
Bob Powell [MVP]
C#, System.Drawing

The October edition of Well Formed is now available.
Find out how to use DirectX in a Windows Forms control
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Blog http://bobpowelldotnet.blogspot.com

Eric said:
I need to draw a wheel. It should look about like the Wheel of Fortune
wheel. I also need to be able to change the colors in each section. I know
how to draw circles and lines but I have no idea how to fill each section
with different colors. Can someone post a little sample code. Perhaps a
circle in 2 pieces that you can change the color?
 
Back
Top