[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

microsoft.public.dotnet.framework.drawing

Bob Powell's "How to use the CreateGraphics method"

joeycalisay

1/13/2005 9:29:00 AM

Mr. Powell suggests to use CreateGraphics outside Paint eventhandler,
OnPaint, OnPaintBackGround in order to obtain the graphics object. At
WndProc method, one can grab a graphics object from the handle of the
control's window (GetWindowDC). When I am handling the WM_NCPAINT message,
what will be the difference of using CreateGraphics and obtaining it from
the Window Handle of the control to draw my custom non-client border?

I think I bumped before on the idea that it will be better to obtain it
using GetWindowDC but I can't seem to find the document that I've read
before. Anyone who can shed a light on this?

Thanks a lot!


3 Answers

Bob Powell

1/13/2005 11:01:00 AM

0

If you read this article...

http://www.bobowell.net/creategr...

You will see that I reccommend NOT using CreateGraphics except under very
specific circumstances. You should certainly not use it in the Paint or
PaintBackground cycles.

When responding to WM_NCPAINT you should use GetWindowDC and wrap the
resulting handle using Graphics.FromHandle

--
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.





"joeycalisay" <hcalisay@_spamkiller_codex-systems.com> wrote in message
news:eIeXDJV%23EHA.1544@TK2MSFTNGP11.phx.gbl...
> Mr. Powell suggests to use CreateGraphics outside Paint eventhandler,
> OnPaint, OnPaintBackGround in order to obtain the graphics object. At
> WndProc method, one can grab a graphics object from the handle of the
> control's window (GetWindowDC). When I am handling the WM_NCPAINT
> message,
> what will be the difference of using CreateGraphics and obtaining it from
> the Window Handle of the control to draw my custom non-client border?
>
> I think I bumped before on the idea that it will be better to obtain it
> using GetWindowDC but I can't seem to find the document that I've read
> before. Anyone who can shed a light on this?
>
> Thanks a lot!
>
>


joeycalisay

1/14/2005 1:13:00 AM

0

Thanks Mr. Powell.

Anyone who can provide information on what will happen if I use
CreateGraphics in handling WM_NCPAINT and its disadvantage if there are? I
haven't tested it though...

"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:O%23PZH9V%23EHA.2180@TK2MSFTNGP10.phx.gbl...
> If you read this article...
>
> http://www.bobowell.net/creategr...
>
> You will see that I reccommend NOT using CreateGraphics except under very
> specific circumstances. You should certainly not use it in the Paint or
> PaintBackground cycles.
>
> When responding to WM_NCPAINT you should use GetWindowDC and wrap the
> resulting handle using Graphics.FromHandle
>
> --
> 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.
>
>
>
>
>
> "joeycalisay" <hcalisay@_spamkiller_codex-systems.com> wrote in message
> news:eIeXDJV%23EHA.1544@TK2MSFTNGP11.phx.gbl...
> > Mr. Powell suggests to use CreateGraphics outside Paint eventhandler,
> > OnPaint, OnPaintBackGround in order to obtain the graphics object. At
> > WndProc method, one can grab a graphics object from the handle of the
> > control's window (GetWindowDC). When I am handling the WM_NCPAINT
> > message,
> > what will be the difference of using CreateGraphics and obtaining it
from
> > the Window Handle of the control to draw my custom non-client border?
> >
> > I think I bumped before on the idea that it will be better to obtain it
> > using GetWindowDC but I can't seem to find the document that I've read
> > before. Anyone who can shed a light on this?
> >
> > Thanks a lot!
> >
> >
>
>


Bob Powell

1/14/2005 11:12:00 AM

0

In WM_NCPAINT you get the wrong Graphics object. You MUST use interop and
the GetWindowDC API

--
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.





"joeycalisay" <hcalisay@_spamkiller_codex-systems.com> wrote in message
news:%23kwWlYd%23EHA.3700@tk2msftngp13.phx.gbl...
> Thanks Mr. Powell.
>
> Anyone who can provide information on what will happen if I use
> CreateGraphics in handling WM_NCPAINT and its disadvantage if there are?
> I
> haven't tested it though...
>
> "Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
> news:O%23PZH9V%23EHA.2180@TK2MSFTNGP10.phx.gbl...
>> If you read this article...
>>
>> http://www.bobowell.net/creategr...
>>
>> You will see that I reccommend NOT using CreateGraphics except under very
>> specific circumstances. You should certainly not use it in the Paint or
>> PaintBackground cycles.
>>
>> When responding to WM_NCPAINT you should use GetWindowDC and wrap the
>> resulting handle using Graphics.FromHandle
>>
>> --
>> 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.
>>
>>
>>
>>
>>
>> "joeycalisay" <hcalisay@_spamkiller_codex-systems.com> wrote in message
>> news:eIeXDJV%23EHA.1544@TK2MSFTNGP11.phx.gbl...
>> > Mr. Powell suggests to use CreateGraphics outside Paint eventhandler,
>> > OnPaint, OnPaintBackGround in order to obtain the graphics object. At
>> > WndProc method, one can grab a graphics object from the handle of the
>> > control's window (GetWindowDC). When I am handling the WM_NCPAINT
>> > message,
>> > what will be the difference of using CreateGraphics and obtaining it
> from
>> > the Window Handle of the control to draw my custom non-client border?
>> >
>> > I think I bumped before on the idea that it will be better to obtain it
>> > using GetWindowDC but I can't seem to find the document that I've read
>> > before. Anyone who can shed a light on this?
>> >
>> > Thanks a lot!
>> >
>> >
>>
>>
>
>