[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.drawing

Drawing a qurater of a doughnut

AviD

12/17/2004 7:23:00 PM

Iâ??m trying to draw a quarter of a doughnut using a graphics path. I add two
parallel arcs to the path and then close them. When I draw the path I do get
the quarter, but thereâ?? a parasite line that connecting the two edges of the
inner arc. What will be the way to draw a clean quarter?

--
Avi
American Society of Composers Authors and Publishers
New York, NY

5 Answers

Bob Powell

12/19/2004 3:57:00 PM

0

The trouble with AddArc is that it always draws in the same direction,
counterclockwise, so you are guaranteed to get a convoluted shape from just
adding two arcs to a GraphicsPath.

In order to draw a quarter of a donut, or annulus, the points must be drawn
in anticlockwise order at the start, for the outer edge, and clockwise for
the inner edge.

The code below my signature does this. You'll probably need to modify it but
you get the general idea....

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

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tips...

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

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

C#

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

{

GraphicsPath pth=new GraphicsPath(FillMode.Winding);

ArrayList lst=new ArrayList();

float a=0;

for(; a<=90; a+=2)

lst.Add(new
PointF((float)Math.Cos(Radians(a)),-(float)Math.Sin(Radians(a))));

for(; a>=0; a-=2)

lst.Add(new
PointF(0.5f*(float)Math.Cos(Radians(a)),-0.5f*(float)Math.Sin(Radians(a))));

lst.Add(lst[0]);

PointF[] pf=new PointF[lst.Count];

lst.CopyTo(pf,0);

pth.AddLines(pf);

lst.Clear();

pth.Transform(new Matrix(100,0,0,100,100,100));

e.Graphics.FillPath(Brushes.Blue,pth);

pth.Dispose();

}

VB

Private Sub Form1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs)
Dim pth As GraphicsPath = New GraphicsPath (FillMode.Winding)
Dim lst As ArrayList = New ArrayList ()
Dim a As Single = 0
While a <= 90
lst.Add(New PointF (CType(Math.Cos(Radians(a)),
Single), -CType(Math.Sin(Radians(a)), Single)))
a += 2
End While
While a >= 0
lst.Add(New PointF (0.5 * CType(Math.Cos(Radians(a)), Single), -0.5 *
CType(Math.Sin(Radians(a)), Single)))
a -= 2
End While
lst.Add(lst(0))
Dim pf(lst.Count) As PointF
lst.CopyTo(pf, 0)
pth.AddLines(pf)
lst.Clear()
pth.Transform(New Matrix (100, 0, 0, 100, 100, 100))
e.Graphics.FillPath(Brushes.Blue, pth)
pth.Dispose()
End Sub




"AviD" <avi@newsgroup.nospam> wrote in message
news:1E2347C2-4D8C-43F5-BF85-D7AD1265C19D@microsoft.com...
> I'm trying to draw a quarter of a doughnut using a graphics path. I add
two
> parallel arcs to the path and then close them. When I draw the path I do
get
> the quarter, but there' a parasite line that connecting the two edges of
the
> inner arc. What will be the way to draw a clean quarter?
>
> --
> Avi
> American Society of Composers Authors and Publishers
> New York, NY
>


AviD

12/20/2004 12:49:00 PM

0

Hi Bob,
Thanks for the reply and the code. You are right - arcs are tricky. The
order of the elements is crucial. I've found out that I could create the
correct path if I started with the outer arc, a line , inner arc and closing
line. I'll try to use you code as well.

"Bob Powell [MVP]" wrote:

> The trouble with AddArc is that it always draws in the same direction,
> counterclockwise, so you are guaranteed to get a convoluted shape from just
> adding two arcs to a GraphicsPath.
>
> In order to draw a quarter of a donut, or annulus, the points must be drawn
> in anticlockwise order at the start, for the outer edge, and clockwise for
> the inner edge.
>
> The code below my signature does this. You'll probably need to modify it but
> you get the general idea....
>
> --
> Bob Powell [MVP]
> Visual C#, System.Drawing
>
> Find great Windows Forms articles in Windows Forms Tips and Tricks
> http://www.bobpowell.net/tips...
>
> Answer those GDI+ questions with the GDI+ FAQ
> http://www.bobpowell.net/f...
>
> All new articles provide code in C# and VB.NET.
> Subscribe to the RSS feeds provided and never miss a new article.
>
> C#
>
> private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs
> e)
>
> {
>
> GraphicsPath pth=new GraphicsPath(FillMode.Winding);
>
> ArrayList lst=new ArrayList();
>
> float a=0;
>
> for(; a<=90; a+=2)
>
> lst.Add(new
> PointF((float)Math.Cos(Radians(a)),-(float)Math.Sin(Radians(a))));
>
> for(; a>=0; a-=2)
>
> lst.Add(new
> PointF(0.5f*(float)Math.Cos(Radians(a)),-0.5f*(float)Math.Sin(Radians(a))));
>
> lst.Add(lst[0]);
>
> PointF[] pf=new PointF[lst.Count];
>
> lst.CopyTo(pf,0);
>
> pth.AddLines(pf);
>
> lst.Clear();
>
> pth.Transform(new Matrix(100,0,0,100,100,100));
>
> e.Graphics.FillPath(Brushes.Blue,pth);
>
> pth.Dispose();
>
> }
>
> VB
>
> Private Sub Form1_Paint(ByVal sender As Object, ByVal e As
> System.Windows.Forms.PaintEventArgs)
> Dim pth As GraphicsPath = New GraphicsPath (FillMode.Winding)
> Dim lst As ArrayList = New ArrayList ()
> Dim a As Single = 0
> While a <= 90
> lst.Add(New PointF (CType(Math.Cos(Radians(a)),
> Single), -CType(Math.Sin(Radians(a)), Single)))
> a += 2
> End While
> While a >= 0
> lst.Add(New PointF (0.5 * CType(Math.Cos(Radians(a)), Single), -0.5 *
> CType(Math.Sin(Radians(a)), Single)))
> a -= 2
> End While
> lst.Add(lst(0))
> Dim pf(lst.Count) As PointF
> lst.CopyTo(pf, 0)
> pth.AddLines(pf)
> lst.Clear()
> pth.Transform(New Matrix (100, 0, 0, 100, 100, 100))
> e.Graphics.FillPath(Brushes.Blue, pth)
> pth.Dispose()
> End Sub
>
>
>
>
> "AviD" <avi@newsgroup.nospam> wrote in message
> news:1E2347C2-4D8C-43F5-BF85-D7AD1265C19D@microsoft.com...
> > I'm trying to draw a quarter of a doughnut using a graphics path. I add
> two
> > parallel arcs to the path and then close them. When I draw the path I do
> get
> > the quarter, but there' a parasite line that connecting the two edges of
> the
> > inner arc. What will be the way to draw a clean quarter?
> >
> > --
> > Avi
> > American Society of Composers Authors and Publishers
> > New York, NY
> >
>
>
>

Bob Powell

12/20/2004 8:56:00 PM

0

Remember also to use Winding and not Alternate for your fill-mode. That way
you can draw the odd arcs and have the renderer ignore the holes in the
region.

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

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tips...

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

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





"AviD" <avi@newsgroup.nospam> wrote in message
news:993E6470-5475-4B0E-ADDC-7C67F581A929@microsoft.com...
> Hi Bob,
> Thanks for the reply and the code. You are right - arcs are tricky. The
> order of the elements is crucial. I've found out that I could create the
> correct path if I started with the outer arc, a line , inner arc and
closing
> line. I'll try to use you code as well.
>
> "Bob Powell [MVP]" wrote:
>
> > The trouble with AddArc is that it always draws in the same direction,
> > counterclockwise, so you are guaranteed to get a convoluted shape from
just
> > adding two arcs to a GraphicsPath.
> >
> > In order to draw a quarter of a donut, or annulus, the points must be
drawn
> > in anticlockwise order at the start, for the outer edge, and clockwise
for
> > the inner edge.
> >
> > The code below my signature does this. You'll probably need to modify it
but
> > you get the general idea....
> >
> > --
> > Bob Powell [MVP]
> > Visual C#, System.Drawing
> >
> > Find great Windows Forms articles in Windows Forms Tips and Tricks
> > http://www.bobpowell.net/tips...
> >
> > Answer those GDI+ questions with the GDI+ FAQ
> > http://www.bobpowell.net/f...
> >
> > All new articles provide code in C# and VB.NET.
> > Subscribe to the RSS feeds provided and never miss a new article.
> >
> > C#
> >
> > private void Form1_Paint(object sender,
System.Windows.Forms.PaintEventArgs
> > e)
> >
> > {
> >
> > GraphicsPath pth=new GraphicsPath(FillMode.Winding);
> >
> > ArrayList lst=new ArrayList();
> >
> > float a=0;
> >
> > for(; a<=90; a+=2)
> >
> > lst.Add(new
> > PointF((float)Math.Cos(Radians(a)),-(float)Math.Sin(Radians(a))));
> >
> > for(; a>=0; a-=2)
> >
> > lst.Add(new
> >
PointF(0.5f*(float)Math.Cos(Radians(a)),-0.5f*(float)Math.Sin(Radians(a))));
> >
> > lst.Add(lst[0]);
> >
> > PointF[] pf=new PointF[lst.Count];
> >
> > lst.CopyTo(pf,0);
> >
> > pth.AddLines(pf);
> >
> > lst.Clear();
> >
> > pth.Transform(new Matrix(100,0,0,100,100,100));
> >
> > e.Graphics.FillPath(Brushes.Blue,pth);
> >
> > pth.Dispose();
> >
> > }
> >
> > VB
> >
> > Private Sub Form1_Paint(ByVal sender As Object, ByVal e As
> > System.Windows.Forms.PaintEventArgs)
> > Dim pth As GraphicsPath = New GraphicsPath (FillMode.Winding)
> > Dim lst As ArrayList = New ArrayList ()
> > Dim a As Single = 0
> > While a <= 90
> > lst.Add(New PointF (CType(Math.Cos(Radians(a)),
> > Single), -CType(Math.Sin(Radians(a)), Single)))
> > a += 2
> > End While
> > While a >= 0
> > lst.Add(New PointF (0.5 * CType(Math.Cos(Radians(a)), Single), -0.5 *
> > CType(Math.Sin(Radians(a)), Single)))
> > a -= 2
> > End While
> > lst.Add(lst(0))
> > Dim pf(lst.Count) As PointF
> > lst.CopyTo(pf, 0)
> > pth.AddLines(pf)
> > lst.Clear()
> > pth.Transform(New Matrix (100, 0, 0, 100, 100, 100))
> > e.Graphics.FillPath(Brushes.Blue, pth)
> > pth.Dispose()
> > End Sub
> >
> >
> >
> >
> > "AviD" <avi@newsgroup.nospam> wrote in message
> > news:1E2347C2-4D8C-43F5-BF85-D7AD1265C19D@microsoft.com...
> > > I'm trying to draw a quarter of a doughnut using a graphics path. I
add
> > two
> > > parallel arcs to the path and then close them. When I draw the path I
do
> > get
> > > the quarter, but there' a parasite line that connecting the two edges
of
> > the
> > > inner arc. What will be the way to draw a clean quarter?
> > >
> > > --
> > > Avi
> > > American Society of Composers Authors and Publishers
> > > New York, NY
> > >
> >
> >
> >


Avi Dubnikov

12/21/2004 3:38:00 AM

0

Hi Bob,
Thanks again for the message. After some long trials and errors I think I
can draw all four annulusi (annuluses?, this is a very dangerous name...)
using arcs and lines, into graphics paths.
Private Sub AnnulusPainter(ByVal g As Graphics)

g.SmoothingMode = SmoothingMode.AntiAlias

Dim SW As Integer = 20

Dim rect1 As New Rectangle(50, 50, 100, 100)

Dim gp1 As New GraphicsPath(FillMode.Alternate)

Dim gp2 As New GraphicsPath(FillMode.Alternate)

Dim gp3 As New GraphicsPath(FillMode.Alternate)

Dim gp4 As New GraphicsPath(FillMode.Alternate)

Dim rect2 As Rectangle = rect1



rect1.Inflate(-SW, -SW)



gp1.AddArc(rect1, 270, 90)

gp1.AddArc(rect2, 270, 90)

gp1.AddLine(rect1.X + CInt(rect1.Width / 2), rect1.Y, rect2.X +
CInt(rect2.Width / 2), rect2.Y)

gp1.AddLine(rect1.X + rect1.Width, rect1.Y + CInt(rect1.Height / 2),
rect2.X + rect2.Width, CInt(rect2.Y + rect2.Height / 2))

g.FillPath(Brushes.Purple, gp1)

gp1.Dispose()



gp2.AddArc(rect1, 180, 90)

gp2.AddLine(rect1.X + CInt(rect1.Width / 2), rect1.Y, rect2.X +
CInt(rect2.Width / 2), rect2.Y)

gp2.AddLine(rect1.X, rect1.Y + CInt(rect1.Height / 2), rect2.X,
rect2.Y + CInt(rect2.Height / 2))

gp2.AddArc(rect2, 180, 90)

g.FillPath(New SolidBrush(Color.Blue), gp2)

gp2.Dispose()



gp3.AddArc(rect1, 0, 90)

gp3.AddLine(rect1.X + rect1.Width, rect1.Y + CInt(rect1.Height / 2),
rect2.X + rect2.Width, CInt(rect2.Y + rect2.Height / 2))

gp3.AddArc(rect2, 0, 90)

gp3.AddLine(rect2.X + CInt(rect2.Width / 2), rect2.Y + rect2.Height,
rect2.X + CInt(rect2.Width / 2), rect1.Y + rect1.Height)

g.FillPath(Brushes.Red, gp3)

gp3.Dispose()



gp4.AddArc(rect1, 90, 90)

gp4.AddLine(rect2.X + CInt(rect2.Width / 2), rect2.Y +
rect2.Height, rect1.X + CInt(rect1.Width / 2), rect1.Y + rect1.Height)

gp4.AddLine(rect2.X, rect2.Y + CInt(rect2.Height / 2), rect1.X,
rect1.Y + CInt(rect1.Height / 2))

gp4.AddArc(rect2, 90, 90)

g.FillPath(Brushes.Pink, gp4)

gp4.Dispose()



g.DrawRectangle(New Pen(Color.Yellow), rect1)

g.DrawRectangle(New Pen(Color.Green), rect2)

End Sub


"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:%23AbbHZt5EHA.2156@TK2MSFTNGP10.phx.gbl...
> Remember also to use Winding and not Alternate for your fill-mode. That
> way
> you can draw the odd arcs and have the renderer ignore the holes in the
> region.
>
> --
> Bob Powell [MVP]
> Visual C#, System.Drawing
>
> Find great Windows Forms articles in Windows Forms Tips and Tricks
> http://www.bobpowell.net/tips...
>
> Answer those GDI+ questions with the GDI+ FAQ
> http://www.bobpowell.net/f...
>
> All new articles provide code in C# and VB.NET.
> Subscribe to the RSS feeds provided and never miss a new article.
>
>
>
>
>
> "AviD" <avi@newsgroup.nospam> wrote in message
> news:993E6470-5475-4B0E-ADDC-7C67F581A929@microsoft.com...
>> Hi Bob,
>> Thanks for the reply and the code. You are right - arcs are tricky. The
>> order of the elements is crucial. I've found out that I could create the
>> correct path if I started with the outer arc, a line , inner arc and
> closing
>> line. I'll try to use you code as well.
>>
>> "Bob Powell [MVP]" wrote:
>>
>> > The trouble with AddArc is that it always draws in the same direction,
>> > counterclockwise, so you are guaranteed to get a convoluted shape from
> just
>> > adding two arcs to a GraphicsPath.
>> >
>> > In order to draw a quarter of a donut, or annulus, the points must be
> drawn
>> > in anticlockwise order at the start, for the outer edge, and clockwise
> for
>> > the inner edge.
>> >
>> > The code below my signature does this. You'll probably need to modify
>> > it
> but
>> > you get the general idea....
>> >
>> > --
>> > Bob Powell [MVP]
>> > Visual C#, System.Drawing
>> >
>> > Find great Windows Forms articles in Windows Forms Tips and Tricks
>> > http://www.bobpowell.net/tips...
>> >
>> > Answer those GDI+ questions with the GDI+ FAQ
>> > http://www.bobpowell.net/f...
>> >
>> > All new articles provide code in C# and VB.NET.
>> > Subscribe to the RSS feeds provided and never miss a new article.
>> >
>> > C#
>> >
>> > private void Form1_Paint(object sender,
> System.Windows.Forms.PaintEventArgs
>> > e)
>> >
>> > {
>> >
>> > GraphicsPath pth=new GraphicsPath(FillMode.Winding);
>> >
>> > ArrayList lst=new ArrayList();
>> >
>> > float a=0;
>> >
>> > for(; a<=90; a+=2)
>> >
>> > lst.Add(new
>> > PointF((float)Math.Cos(Radians(a)),-(float)Math.Sin(Radians(a))));
>> >
>> > for(; a>=0; a-=2)
>> >
>> > lst.Add(new
>> >
> PointF(0.5f*(float)Math.Cos(Radians(a)),-0.5f*(float)Math.Sin(Radians(a))));
>> >
>> > lst.Add(lst[0]);
>> >
>> > PointF[] pf=new PointF[lst.Count];
>> >
>> > lst.CopyTo(pf,0);
>> >
>> > pth.AddLines(pf);
>> >
>> > lst.Clear();
>> >
>> > pth.Transform(new Matrix(100,0,0,100,100,100));
>> >
>> > e.Graphics.FillPath(Brushes.Blue,pth);
>> >
>> > pth.Dispose();
>> >
>> > }
>> >
>> > VB
>> >
>> > Private Sub Form1_Paint(ByVal sender As Object, ByVal e As
>> > System.Windows.Forms.PaintEventArgs)
>> > Dim pth As GraphicsPath = New GraphicsPath (FillMode.Winding)
>> > Dim lst As ArrayList = New ArrayList ()
>> > Dim a As Single = 0
>> > While a <= 90
>> > lst.Add(New PointF (CType(Math.Cos(Radians(a)),
>> > Single), -CType(Math.Sin(Radians(a)), Single)))
>> > a += 2
>> > End While
>> > While a >= 0
>> > lst.Add(New PointF (0.5 * CType(Math.Cos(Radians(a)), Single), -0.5
>> > *
>> > CType(Math.Sin(Radians(a)), Single)))
>> > a -= 2
>> > End While
>> > lst.Add(lst(0))
>> > Dim pf(lst.Count) As PointF
>> > lst.CopyTo(pf, 0)
>> > pth.AddLines(pf)
>> > lst.Clear()
>> > pth.Transform(New Matrix (100, 0, 0, 100, 100, 100))
>> > e.Graphics.FillPath(Brushes.Blue, pth)
>> > pth.Dispose()
>> > End Sub
>> >
>> >
>> >
>> >
>> > "AviD" <avi@newsgroup.nospam> wrote in message
>> > news:1E2347C2-4D8C-43F5-BF85-D7AD1265C19D@microsoft.com...
>> > > I'm trying to draw a quarter of a doughnut using a graphics path. I
> add
>> > two
>> > > parallel arcs to the path and then close them. When I draw the path
>> > > I
> do
>> > get
>> > > the quarter, but there' a parasite line that connecting the two
>> > > edges
> of
>> > the
>> > > inner arc. What will be the way to draw a clean quarter?
>> > >
>> > > --
>> > > Avi
>> > > American Society of Composers Authors and Publishers
>> > > New York, NY
>> > >
>> >
>> >
>> >
>
>


Bob Powell

12/21/2004 11:09:00 AM

0

Yup, looks good!

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

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tips...

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

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





"Avi Dubnikov" <dubnikova@ascap.com> wrote in message
news:uD3OJ5w5EHA.2676@TK2MSFTNGP12.phx.gbl...
> Hi Bob,
> Thanks again for the message. After some long trials and errors I think I
> can draw all four annulusi (annuluses?, this is a very dangerous name...)
> using arcs and lines, into graphics paths.
> Private Sub AnnulusPainter(ByVal g As Graphics)
>
> g.SmoothingMode = SmoothingMode.AntiAlias
>
> Dim SW As Integer = 20
>
> Dim rect1 As New Rectangle(50, 50, 100, 100)
>
> Dim gp1 As New GraphicsPath(FillMode.Alternate)
>
> Dim gp2 As New GraphicsPath(FillMode.Alternate)
>
> Dim gp3 As New GraphicsPath(FillMode.Alternate)
>
> Dim gp4 As New GraphicsPath(FillMode.Alternate)
>
> Dim rect2 As Rectangle = rect1
>
>
>
> rect1.Inflate(-SW, -SW)
>
>
>
> gp1.AddArc(rect1, 270, 90)
>
> gp1.AddArc(rect2, 270, 90)
>
> gp1.AddLine(rect1.X + CInt(rect1.Width / 2), rect1.Y, rect2.X +
> CInt(rect2.Width / 2), rect2.Y)
>
> gp1.AddLine(rect1.X + rect1.Width, rect1.Y + CInt(rect1.Height /
2),
> rect2.X + rect2.Width, CInt(rect2.Y + rect2.Height / 2))
>
> g.FillPath(Brushes.Purple, gp1)
>
> gp1.Dispose()
>
>
>
> gp2.AddArc(rect1, 180, 90)
>
> gp2.AddLine(rect1.X + CInt(rect1.Width / 2), rect1.Y, rect2.X +
> CInt(rect2.Width / 2), rect2.Y)
>
> gp2.AddLine(rect1.X, rect1.Y + CInt(rect1.Height / 2), rect2.X,
> rect2.Y + CInt(rect2.Height / 2))
>
> gp2.AddArc(rect2, 180, 90)
>
> g.FillPath(New SolidBrush(Color.Blue), gp2)
>
> gp2.Dispose()
>
>
>
> gp3.AddArc(rect1, 0, 90)
>
> gp3.AddLine(rect1.X + rect1.Width, rect1.Y + CInt(rect1.Height /
2),
> rect2.X + rect2.Width, CInt(rect2.Y + rect2.Height / 2))
>
> gp3.AddArc(rect2, 0, 90)
>
> gp3.AddLine(rect2.X + CInt(rect2.Width / 2), rect2.Y +
rect2.Height,
> rect2.X + CInt(rect2.Width / 2), rect1.Y + rect1.Height)
>
> g.FillPath(Brushes.Red, gp3)
>
> gp3.Dispose()
>
>
>
> gp4.AddArc(rect1, 90, 90)
>
> gp4.AddLine(rect2.X + CInt(rect2.Width / 2), rect2.Y +
> rect2.Height, rect1.X + CInt(rect1.Width / 2), rect1.Y + rect1.Height)
>
> gp4.AddLine(rect2.X, rect2.Y + CInt(rect2.Height / 2), rect1.X,
> rect1.Y + CInt(rect1.Height / 2))
>
> gp4.AddArc(rect2, 90, 90)
>
> g.FillPath(Brushes.Pink, gp4)
>
> gp4.Dispose()
>
>
>
> g.DrawRectangle(New Pen(Color.Yellow), rect1)
>
> g.DrawRectangle(New Pen(Color.Green), rect2)
>
> End Sub
>
>
> "Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
> news:%23AbbHZt5EHA.2156@TK2MSFTNGP10.phx.gbl...
> > Remember also to use Winding and not Alternate for your fill-mode. That
> > way
> > you can draw the odd arcs and have the renderer ignore the holes in the
> > region.
> >
> > --
> > Bob Powell [MVP]
> > Visual C#, System.Drawing
> >
> > Find great Windows Forms articles in Windows Forms Tips and Tricks
> > http://www.bobpowell.net/tips...
> >
> > Answer those GDI+ questions with the GDI+ FAQ
> > http://www.bobpowell.net/f...
> >
> > All new articles provide code in C# and VB.NET.
> > Subscribe to the RSS feeds provided and never miss a new article.
> >
> >
> >
> >
> >
> > "AviD" <avi@newsgroup.nospam> wrote in message
> > news:993E6470-5475-4B0E-ADDC-7C67F581A929@microsoft.com...
> >> Hi Bob,
> >> Thanks for the reply and the code. You are right - arcs are tricky.
The
> >> order of the elements is crucial. I've found out that I could create
the
> >> correct path if I started with the outer arc, a line , inner arc and
> > closing
> >> line. I'll try to use you code as well.
> >>
> >> "Bob Powell [MVP]" wrote:
> >>
> >> > The trouble with AddArc is that it always draws in the same
direction,
> >> > counterclockwise, so you are guaranteed to get a convoluted shape
from
> > just
> >> > adding two arcs to a GraphicsPath.
> >> >
> >> > In order to draw a quarter of a donut, or annulus, the points must be
> > drawn
> >> > in anticlockwise order at the start, for the outer edge, and
clockwise
> > for
> >> > the inner edge.
> >> >
> >> > The code below my signature does this. You'll probably need to modify
> >> > it
> > but
> >> > you get the general idea....
> >> >
> >> > --
> >> > Bob Powell [MVP]
> >> > Visual C#, System.Drawing
> >> >
> >> > Find great Windows Forms articles in Windows Forms Tips and Tricks
> >> > http://www.bobpowell.net/tips...
> >> >
> >> > Answer those GDI+ questions with the GDI+ FAQ
> >> > http://www.bobpowell.net/f...
> >> >
> >> > All new articles provide code in C# and VB.NET.
> >> > Subscribe to the RSS feeds provided and never miss a new article.
> >> >
> >> > C#
> >> >
> >> > private void Form1_Paint(object sender,
> > System.Windows.Forms.PaintEventArgs
> >> > e)
> >> >
> >> > {
> >> >
> >> > GraphicsPath pth=new GraphicsPath(FillMode.Winding);
> >> >
> >> > ArrayList lst=new ArrayList();
> >> >
> >> > float a=0;
> >> >
> >> > for(; a<=90; a+=2)
> >> >
> >> > lst.Add(new
> >> > PointF((float)Math.Cos(Radians(a)),-(float)Math.Sin(Radians(a))));
> >> >
> >> > for(; a>=0; a-=2)
> >> >
> >> > lst.Add(new
> >> >
> >
PointF(0.5f*(float)Math.Cos(Radians(a)),-0.5f*(float)Math.Sin(Radians(a))));
> >> >
> >> > lst.Add(lst[0]);
> >> >
> >> > PointF[] pf=new PointF[lst.Count];
> >> >
> >> > lst.CopyTo(pf,0);
> >> >
> >> > pth.AddLines(pf);
> >> >
> >> > lst.Clear();
> >> >
> >> > pth.Transform(new Matrix(100,0,0,100,100,100));
> >> >
> >> > e.Graphics.FillPath(Brushes.Blue,pth);
> >> >
> >> > pth.Dispose();
> >> >
> >> > }
> >> >
> >> > VB
> >> >
> >> > Private Sub Form1_Paint(ByVal sender As Object, ByVal e As
> >> > System.Windows.Forms.PaintEventArgs)
> >> > Dim pth As GraphicsPath = New GraphicsPath (FillMode.Winding)
> >> > Dim lst As ArrayList = New ArrayList ()
> >> > Dim a As Single = 0
> >> > While a <= 90
> >> > lst.Add(New PointF (CType(Math.Cos(Radians(a)),
> >> > Single), -CType(Math.Sin(Radians(a)), Single)))
> >> > a += 2
> >> > End While
> >> > While a >= 0
> >> > lst.Add(New PointF (0.5 * CType(Math.Cos(Radians(a)),
Single), -0.5
> >> > *
> >> > CType(Math.Sin(Radians(a)), Single)))
> >> > a -= 2
> >> > End While
> >> > lst.Add(lst(0))
> >> > Dim pf(lst.Count) As PointF
> >> > lst.CopyTo(pf, 0)
> >> > pth.AddLines(pf)
> >> > lst.Clear()
> >> > pth.Transform(New Matrix (100, 0, 0, 100, 100, 100))
> >> > e.Graphics.FillPath(Brushes.Blue, pth)
> >> > pth.Dispose()
> >> > End Sub
> >> >
> >> >
> >> >
> >> >
> >> > "AviD" <avi@newsgroup.nospam> wrote in message
> >> > news:1E2347C2-4D8C-43F5-BF85-D7AD1265C19D@microsoft.com...
> >> > > I'm trying to draw a quarter of a doughnut using a graphics path. I
> > add
> >> > two
> >> > > parallel arcs to the path and then close them. When I draw the
path
> >> > > I
> > do
> >> > get
> >> > > the quarter, but there' a parasite line that connecting the two
> >> > > edges
> > of
> >> > the
> >> > > inner arc. What will be the way to draw a clean quarter?
> >> > >
> >> > > --
> >> > > Avi
> >> > > American Society of Composers Authors and Publishers
> >> > > New York, NY
> >> > >
> >> >
> >> >
> >> >
> >
> >
>
>