A developer's NIGHTMAIRE: paint sequence in a form

  • Thread starter Thread starter news.microsoft.com
  • Start date Start date
N

news.microsoft.com

Can someone give me a suggestion about how WinForm handle the sequence of
controls paint and user paint graphic object ?

the problem:
1. use the winform wizard to generate an application.
2. Drop a few buttons on the form.
3. In mouseup event, call Invalidate()
4. In the Paint event, add this line:
e.Graphics.DrawRectangle(new Brush(Color.LightBlue, 3), 5, 5, 50, 50);

the new rectangle is always drawn under the button controls. How can I draw
a rectangle above button controls?

Cheers
Mike
 
* "news.microsoft.com said:
Can someone give me a suggestion about how WinForm handle the sequence of
controls paint and user paint graphic object ?

the problem:
1. use the winform wizard to generate an application.
2. Drop a few buttons on the form.
3. In mouseup event, call Invalidate()
4. In the Paint event, add this line:
e.Graphics.DrawRectangle(new Brush(Color.LightBlue, 3), 5, 5, 50, 50);

the new rectangle is always drawn under the button controls. How can I draw
a rectangle above button controls?

You simply cannot. Buttons are separate windows that are placed on the
form like pictures on a wall. Painting the wall won't change the
appearance of the pictures.
 
The button controls are windows in their own right and so the areas they
occupy are clipped out of the form client drawing area.

You _can_ draw on the desktop but it's a messy and problem-fraught process.

You can also use a layered control but it's a bit complex.

Why do you want to draw on top of controls? It's very bad practice...

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

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
 
Thanks for replying my email.

Here is the story:

I am trying to build something similar to MS ListView control in Thumbnail
mode. I also want to give user the ability to use mouse to do group
selection.

In ListView control Thumbnail mode, if you click on the view and drag your
mouse, you will see the rectangle that is drawn above the items.

My problem is: how can I implement the same function?

Cheers
Mike
 
Back
Top