Re: Difference between 'this.CreateGraphics()' and 'Graphics.FromHdc(hDC);'
- From: "pigeonrandle" <pigeonrandle@xxxxxxxxxxx>
- Date: 4 Dec 2006 04:48:13 -0800
Err...Problem created.
Now the drop down is a solid black color, and none of the text is
displayed. I now see why the contrived method was used in the first
place ...
it allowed user painting of some of the control whilst letting the text
drawing continue as expected.
Is there a way to accomplish this properly? To be honest, i dont want
to have to write loads of drawing code (that is already there) just
because i want to draw a flat button and flat border which wouldnt
obscure the text anyway.
Any comments?
James Randle
pigeonrandle wrote:
Problem solved!
placing
this.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint,
true);
in the constructor (UserPaint being the important bit) has restored the
missing paint event, and the draw flat button code can be called from
an overriden onpaint().
Thanks to anyone half writing a reply as i write mine, and again thanks
to Bob for pointing me in the right direction.
James Randle.
pigeonrandle wrote:
I just tried to call the drawing functions from an overriden OnPaint()
and the combo has reverted to its 3d appearance. Does this mean i have
to break the rules, or am i doing something wrong?
Arrggghhh!
James Randle.
pigeonrandle wrote:
Bob (again!),
Hi. I've had a read through the GDI+ FAQ. Am i correct in the following
suggestions?
1) do WM_PAINT control painting in overridden OnPaint() event (after
base.OnPaint(e))
2) WM_NC_PAINT still needs to be handled in WndProc as it uses 'fancy
stuff'
I just read that the combobox has no 'non-client' area so can i discard
WM_NC_PAINT all together?
Thanks and thanks again,
James Randle.
Bob Powell [MVP] wrote:
CreateGraphics will get you a Graphics object based on the client area of
the window.
FromHdc using the handle from GetWindowDC will return a graphics object
based on the whole window including the non-client area. This DC is normally
only used by the system unless you want to do clever stuff like override the
non client drawing.
You should really use niether. See the GDI+ FAQ for how and when to get a
Graphics object.
--
Bob Powell [MVP]
Visual C#, System.Drawing
Ramuseco Limited .NET consulting
http://www.ramuseco.com
Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm
All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
"pigeonrandle" <pigeonrandle@xxxxxxxxxxx> wrote in message
news:1165194940.231084.167620@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi,
Please pity me, i am on a dial-up connection for the first time in 5
years :( !
Does anyone know how the resulting Graphics objects differ ...? What i
really mean is can someone explain it to me please?
A)
[DllImport("user32.dll")] protected static extern IntPtr GetWindowDC
(IntPtr hWnd );
hDC = GetWindowDC(this.Handle);
g_dc = Graphics.FromHdc(hDC);
B)
Graphics g = this.CreateGraphics();
You have my thanks and full attention,
James Randle.
.
- References:
- Difference between 'this.CreateGraphics()' and 'Graphics.FromHdc(hDC);'
- From: pigeonrandle
- Re: Difference between 'this.CreateGraphics()' and 'Graphics.FromHdc(hDC);'
- From: Bob Powell [MVP]
- Re: Difference between 'this.CreateGraphics()' and 'Graphics.FromHdc(hDC);'
- From: pigeonrandle
- Re: Difference between 'this.CreateGraphics()' and 'Graphics.FromHdc(hDC);'
- From: pigeonrandle
- Re: Difference between 'this.CreateGraphics()' and 'Graphics.FromHdc(hDC);'
- From: pigeonrandle
- Difference between 'this.CreateGraphics()' and 'Graphics.FromHdc(hDC);'
- Prev by Date: WCF and asp.net client
- Next by Date: Re: how to exchange 1234(number) -> bytes sequence
- Previous by thread: Re: Difference between 'this.CreateGraphics()' and 'Graphics.FromHdc(hDC);'
- Next by thread: How to bind the string value to Richtextbox.Rtf in vb.net
- Index(es):