[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

microsoft.public.dotnet.framework.drawing

Creating a GraphicsPath from a Region by hit-testing with Region.IsVisible

Marius.Ebel

1/2/2005 12:08:00 AM

Please excuse my spelling and my grammar, but I'm German.

I have a Region where several figures are combined. I also have the
GraphicsPaths which ware combined in the Region, but I don't know how
to create a procedure which goes along the outline of the region and
adds the points senseful to another GraphicsPath. If anybody has a
solution for my problem, I would be very glad.

Thank you for your answers
Marius Ebel
10 Answers

Mick Doherty

1/2/2005 11:42:00 AM

0

Do you mean this?

myGraphicsPath.FillMode = FillMode.Winding
myGraphicsPath.AddLines(yourGraphicsPath.PathPoints)

--
Mick Doherty
http://dotnetrix.co.uk/no...


"marius ebel" <Marius.Ebel@web.de> wrote in message
news:c1728f52.0501011607.5e5e2539@posting.google.com...
> Please excuse my spelling and my grammar, but I'm German.
>
> I have a Region where several figures are combined. I also have the
> GraphicsPaths which ware combined in the Region, but I don't know how
> to create a procedure which goes along the outline of the region and
> adds the points senseful to another GraphicsPath. If anybody has a
> solution for my problem, I would be very glad.
>
> Thank you for your answers
> Marius Ebel


Marius Ebel

1/2/2005 2:07:00 PM

0

Nearly. But the outline of the separate figures is still visible. Insert
the following code into a Paint-Event procedure, perhaps you'll
understand what my problem is.


GraphicsPath temp = new GraphicsPath();
GraphicsPath final = new GraphicsPath(FillMode.Winding);

temp.AddEllipse(0, 0, 30, 30);
temp.Flatten();
final.AddLines(temp.PathPoints);

temp = new GraphicsPath();
temp.AddEllipse(20, 0, 30, 30);
temp.Flatten();
final.AddLines(temp.PathPoints);

temp = new GraphicsPath();
temp.AddEllipse(10, 15, 30, 3);
temp.Flatten();
final.AddLines(temp.PathPoints);

e.Graphics.DrawPath(Pens.Black, final);



*** Sent via Developersdex http://www.develop... ***
Don't just participate in USENET...get rewarded for it!

Mick Doherty

1/2/2005 4:15:00 PM

0

I see! So you want a DrawRegion method.

I think you're going to have to resort to GDI for that.

\\[System.Runtime.InteropServices.DllImport("gdi32.dll")]
private static extern bool FrameRgn(IntPtr hdc,
IntPtr hrgn, IntPtr hbr, Int16 nWidth, Int16 nHeight);

[System.Runtime.InteropServices.DllImport("gdi32.dll")]
private static extern IntPtr CreateSolidBrush(Int32 crColor );

[System.Runtime.InteropServices.DllImport("gdi32.dll")]
private static extern bool DeleteObject(IntPtr hObject);

private void Form1_Paint(object sender, PaintEventArgs e)
{
GraphicsPath temp = new GraphicsPath(FillMode.Winding);

temp.AddEllipse(0, 0, 30, 30);
temp.AddEllipse(20, 0, 30, 30);
temp.AddEllipse(10, 15, 30, 3);

Region final = new Region(temp);

IntPtr hRgn = final.GetHrgn(e.Graphics);
IntPtr hBrush = CreateSolidBrush(ColorTranslator.ToOle(Color.Blue));
IntPtr hdc = e.Graphics.GetHdc();

FrameRgn(hdc, hRgn, hBrush, 1, 1);

DeleteObject(hBrush);
e.Graphics.ReleaseHdc(hdc);
}
///

--
Mick Doherty
http://dotnetrix.co.uk/no...


Marius Ebel

1/2/2005 7:19:00 PM

0

Thanks a lot!!!! Thank you! I tried 3 days and 4 nights so solve this
problem. Thank you!

Thank you
Marius Ebel



*** Sent via Developersdex http://www.develop... ***
Don't just participate in USENET...get rewarded for it!

Marius Ebel

1/2/2005 7:47:00 PM

0

I have one last question: Is it possible to convert a
System.Drawing.Drawing2D.Brush-Object (and all its subtypes) into a
Win32-API Brush-Object?

Thank you
Marius Ebel



*** Sent via Developersdex http://www.develop... ***
Don't just participate in USENET...get rewarded for it!

Mick Doherty

1/2/2005 10:38:00 PM

0

AFAIK no, you'll have to use GDI brush objects created via DLLImport.

--
Mick Doherty
http://dotnetrix.co.uk/no...


"Marius Ebel" <marius.ebel@web.de> wrote in message
news:%23h6FEPQ8EHA.3260@TK2MSFTNGP14.phx.gbl...
>I have one last question: Is it possible to convert a
> System.Drawing.Drawing2D.Brush-Object (and all its subtypes) into a
> Win32-API Brush-Object?
>
> Thank you
> Marius Ebel
>
>
>
> *** Sent via Developersdex http://www.develop... ***
> Don't just participate in USENET...get rewarded for it!


Marius Ebel

1/3/2005 12:51:00 PM

0

I've found a possibility to use the System.Drawing.Drawing2D.Brush with
the Win32-API. Create a System.Drawing.Bitmap which has the size of the
Region an fill it with your custom System.Drawing.Drawing2D.Brush. Now
you have to create a Win32-PatternBrush by calling CreatePatternBrush()
and draw the outline of the Region. Look at the following code (it's not
real high-performance but there is no other way):

[System.Runtime.InteropServices.DllImport("gdi32.dll")]
private static extern bool FrameRgn(IntPtr hdc,
IntPtr hrgn, IntPtr hbr, Int16 nWidth, Int16 nHeight);

[System.Runtime.InteropServices.DllImport("gdi32.dll")]
private static extern IntPtr CreateSolidBrush(Int32 crColor );

[System.Runtime.InteropServices.DllImport("gdi32.dll")]
private static extern bool DeleteObject(IntPtr hObject);

[System.Runtime.InteropServices.DllImport("gdi32.dll")]
private static extern IntPtr CreateHatchBrush(Int32 fnStyle,
Int32 crColor);

[System.Runtime.InteropServices.DllImport("gdi32.dll")]
private static extern IntPtr CreatePatternBrush(
IntPtr hbmp );

private void Form6_Paint(object sender, PaintEventArgs e)
{
GraphicsPath temp = new GraphicsPath(FillMode.Winding);
GraphicsPath temp2 = new GraphicsPath(FillMode.Winding);
GraphicsPath temp3 = new GraphicsPath(FillMode.Winding);

temp.AddEllipse(0, 0, 30, 30);
temp2.AddEllipse(20, 0, 30, 30);
temp3.AddEllipse(10, 15, 30, 30);

Matrix m = new Matrix();
m.Scale(3.0f, 3.0f);
temp.Transform(m);
temp2.Transform(m);
temp3.Transform(m);

HatchBrush b = new HatchBrush(HatchStyle.Cross, Color.Wheat,
Color.Black);


Region final = new Region(temp);
final.Exclude(temp2);
final.Xor(temp3);

RectangleF finalBounds = final.GetBounds(e.Graphics);
Bitmap bmp = new Bitmap((int)finalBounds.Width + 3,
(int)finalBounds.Height + 3);
LinearGradientBrush lgb = new LinearGradientBrush(new Rectangle(0, 0,
(int)finalBounds.Width + 6, (int)finalBounds.Height + 6), Color.Black,
Color.AliceBlue, 45f);


Graphics g = Graphics.FromImage(bmp);
g.FillRectangle(lgb, new Rectangle(0, 0, bmp.Width + 6, bmp.Height +
6));

g.Dispose();

IntPtr hRgn = final.GetHrgn(e.Graphics);
IntPtr hBrush = CreatePatternBrush(bmp.GetHbitmap(Color.FromArgb(0,
Color.White)));

e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
e.Graphics.FillRegion(Brushes.AliceBlue, final);

IntPtr hdc = e.Graphics.GetHdc();

FrameRgn(hdc, hRgn, hBrush, 3, 3);

DeleteObject(hBrush);
e.Graphics.ReleaseHdc(hdc);
}


*** Sent via Developersdex http://www.develop... ***
Don't just participate in USENET...get rewarded for it!

Mick Doherty

1/3/2005 3:48:00 PM

0

You may also find this one useful, but do not destroy it when you've
finished with it as it is a System Brush

[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern IntPtr GetSysColorBrush(SCB_INDEX nIndex);

private enum SCB_INDEX
{
COLOR_SCROLLBAR,
COLOR_BACKGROUND,
COLOR_ACTIVECAPTION,
COLOR_INACTIVECAPTION,
COLOR_MENU,
COLOR_WINDOW,
COLOR_WINDOWFRAME,
COLOR_MENUTEXT,
COLOR_WINDOWTEXT,
COLOR_CAPTIONTEXT,
COLOR_ACTIVEBORDER,
COLOR_INACTIVEBORDER,
COLOR_APPWORKSPACE,
COLOR_HIGHLIGHT,
COLOR_HIGHLIGHTTEXT,
COLOR_BTNFACE,
COLOR_BTNSHADOW,
COLOR_GRAYTEXT,
COLOR_BTNTEXT,
COLOR_INACTIVECAPTIONTEXT,
COLOR_BTNHIGHLIGHT,
//#if(WINVER >= 0x0400)
COLOR_3DDKSHADOW,
COLOR_3DLIGHT,
COLOR_INFOTEXT,
COLOR_INFOBK,
//#endif /* WINVER >= 0x0400 */
//#if(WINVER >= 0x0500)
COLOR_HOTLIGHT = 26,
COLOR_GRADIENTACTIVECAPTION,
COLOR_GRADIENTINACTIVECAPTION,
//#if(WINVER >= 0x0501)
COLOR_MENUHILIGHT,
COLOR_MENUBAR,
//#endif /* WINVER >= 0x0501 */
//#endif /* WINVER >= 0x0500 */
//#if(WINVER >= 0x0400)
COLOR_DESKTOP = COLOR_BACKGROUND,
COLOR_3DFACE = COLOR_BTNFACE,
COLOR_3DSHADOW = COLOR_BTNSHADOW,
COLOR_3DHIGHLIGHT = COLOR_BTNHIGHLIGHT,
COLOR_3DHILIGHT = COLOR_BTNHIGHLIGHT,
COLOR_BTNHILIGHT = COLOR_BTNHIGHLIGHT
//#endif /* WINVER >= 0x0400 */
}


Then ,if you haven't already done so, add the following line to your forms
Constructor and you will get less flicker (I changed the Matrix scale with a
TrackBar and it was nice and smooth with this line).

SetStyle(ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint,
true);

--
Mick Doherty
http://dotnetrix.co.uk/no...


Marius Ebel

1/4/2005 5:59:00 PM

0

Great! Nothing does flicker anymore. In Order to make this code perfekt:
Is there any way to use antialiasing with the Win32-API? I only found
something called clear type for smoothing text and the
SmoothingMode-Property of the Graphics class does not work with this.

Thank you
Marius Ebel



*** Sent via Developersdex http://www.develop... ***
Don't just participate in USENET...get rewarded for it!

Mick Doherty

1/5/2005 5:38:00 PM

0

I don't know enough about GDI to answer that, but I expect not.

--
Mick Doherty
http://dotnetrix.co.uk/no...


"Marius Ebel" <marius.ebel@web.de> wrote in message
news:%237ubNco8EHA.1296@TK2MSFTNGP10.phx.gbl...
> Great! Nothing does flicker anymore. In Order to make this code perfekt:
> Is there any way to use antialiasing with the Win32-API? I only found
> something called clear type for smoothing text and the
> SmoothingMode-Property of the Graphics class does not work with this.
>
> Thank you
> Marius Ebel
>
>
>
> *** Sent via Developersdex http://www.develop... ***
> Don't just participate in USENET...get rewarded for it!