Graphics 2D path question

D

Damien Sawyer

Hi,

I am creating a control. The control needs to be non-rectangular.

I am creating a graphics path and then adding two overlapping ellipses
to it using the addEllipse method.

I then set this.region ('this' being the control) to a new region,
passing my graphicspath object into the region constructor. This clips
the control to be non-rectangular.

The problem is that, when I add the second ellipse to the path, the
area where the two ellipses overlap is 'negated' or 'toggled'. That
is, I have a huge hole in the middle of my region!

I basically am asking how I create a path that is the UNION of the two
ellipses.


This has been driving me nuts, so thanks in advance!



Damien Sawyer
 
B

Bob Powell [MVP]

When you create the GraphicsPath use the parameterized constructor and selet
the Winding fill-mode.

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

The Image Transition Library wraps up and LED style instrumentation is
available in the June of Well Formed for C# or VB programmers
http://www.bobpowell.net/currentissue.htm

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

The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml
 
S

Stoitcho Goutsev \(100\) [C# MVP]

Hi Demien,

If fill mode doesn't wwork for you why don't you just use Region class'
Interesect method. Create two elliptical regions and intersect them or
something in this line.
 
D

Damien Sawyer

Thanks for that guys!

I used the fillmode.winding enum in the constructor and it worked
perfectly. The suggestion of unioning regions is an excellent one as
well. I'll have a look into that for future things.


Once again, thanks!! :)



DS
 
S

Stoitcho Goutsev \(100\) [C# MVP]

Hi Damien,

I suggested using regions because they are more apporpriate for that
purpose.
The idea is that a region defines an area. That's why operations sucha as
union and intersection are defined for them. The path, how the name
sauggests, is an outline. Even though paths can be filled hit tested in
other words can be a repalcement of regions they cannot be combined in the
same way as regions.

However, I have heard that .NET implemtation of regions is bad. It has
memory leaks and so on. So be carefull. Hopefully in the next version it
will be fixed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top