471,349 Members | 1,176 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,349 software developers and data experts.

Draw over controls

I have a panel that contains a label and a picturebox. When clicked, I
want to draw a rectangle over everything. I can draw the rect and set
the color, no big deal. The problem is because I have to pass the rect
of the panel, it draws on that, and under the other controls. How can
I force it to draw OVER everything else? Ideally this would also be
trackable since the whole thing(panel and children) will be dragable.
This is what i've got right now:

Graphics gfx = selectedCtrl.CreateGraphics();
gfx.FillRectangle(new SolidBrush(Color.FromArgb(100, Color.Crimson)),
selectedCtrl.ClientRectangle);

Where selectedCtrl is the control that was clicked.

Thanks,
Brandon

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
http://www.usenet.com
Aug 4 '08 #1
3 4962
On Aug 4, 6:54*pm, Brandon Arnold <reason...@gmail.comwrote:
I have a panel that contains a label and a picturebox. When clicked, I
want to draw a rectangle over everything. I can draw the rect and set
the color, no big deal. The problem is because I have to pass the rect
of the panel, it draws on that, and under the other controls. How can
I force it to draw OVER everything else? Ideally this would also be
trackable since the whole thing(panel and children) will be dragable.
You shouldn't really draw outside Paint events, because other controls
can decide to redraw at arbitrary moment of time, and will erase your
changes. Instead, just create an empty Panel of the desired color, and
place it where you want your rectangle to be displayed. If you want
some fancy filling on the panel (gradient, etc), then, instead of
changing its BackColor, handle its Paint event and paint whatever you
want in it.
Aug 4 '08 #2
On Mon, 4 Aug 2008 09:07:36 -0700 (PDT), Pavel Minaev
<in****@gmail.comwrote:
>On Aug 4, 6:54*pm, Brandon Arnold <reason...@gmail.comwrote:
>I have a panel that contains a label and a picturebox. When clicked, I
want to draw a rectangle over everything. I can draw the rect and set
the color, no big deal. The problem is because I have to pass the rect
of the panel, it draws on that, and under the other controls. How can
I force it to draw OVER everything else? Ideally this would also be
trackable since the whole thing(panel and children) will be dragable.

You shouldn't really draw outside Paint events, because other controls
can decide to redraw at arbitrary moment of time, and will erase your
changes. Instead, just create an empty Panel of the desired color, and
place it where you want your rectangle to be displayed. If you want
some fancy filling on the panel (gradient, etc), then, instead of
changing its BackColor, handle its Paint event and paint whatever you
want in it.
Right now, I have all my controls and their associated labels together
in seprate panels. Adding more panels seems rather, ugly. Would it
be considered bad form to use them so liberaly? Right now i'm toying
around with that idea. I've placed a panel over the controls(and
parent panel) and when the desired control set is clicked, the overlay
panel is displayed. It works right now with solid colors being set
but i'm having an issue with transparency, but I can work that out.

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
http://www.usenet.com
Aug 4 '08 #3
On Aug 4, 8:26*pm, Brandon Arnold <reason...@gmail.comwrote:
Right now, I have all my controls and their associated labels together
in seprate panels. *Adding more panels seems rather, ugly. *Would it
be considered bad form to use them so liberaly?
Not really. Note also, that in .NET 3.5, there is a bunch of controls
that are specifically useful to "draw" shapes on the form -
RectangleShape, OvalShape, LineShape etc (they come from VB Power Pack
originally). If you have 3.5, you might want to use those instead of
Panel, as they are somewhat more lightweight.
Aug 5 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Crirus | last post: by
2 posts views Thread by Sagaert Johan | last post: by
10 posts views Thread by Phil | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.