By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,992 Members | 934 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,992 IT Pros & Developers. It's quick & easy.

Clip a child control

P: n/a
Hi, I created a control deriving from System.Windows.Forms.Control. In
my own OnPaint method, I can draw and set the clipping and everything
is perfect. But I also added some checkboxes by setting their parent
as my control, and I can seem to get them to clip. They just draw
themselves over anything that's under them, right up to the very edge
of the control. How do I get them to clip where I want? Do I set a
property in my control, set one of their properties, a property of the
Graphics object? I'm really confused here...

I'd appreciate any help or insight...

Thanks,
-Brad

Nov 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
You should be able to use the "Region" property for this purpose.
http://msdn.microsoft.com/library/de...egiontopic.asp

--
Tim Wilson
..Net Compact Framework MVP

"BradBrigade" <si********@hotmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
Hi, I created a control deriving from System.Windows.Forms.Control. In
my own OnPaint method, I can draw and set the clipping and everything
is perfect. But I also added some checkboxes by setting their parent
as my control, and I can seem to get them to clip. They just draw
themselves over anything that's under them, right up to the very edge
of the control. How do I get them to clip where I want? Do I set a
property in my control, set one of their properties, a property of the
Graphics object? I'm really confused here...

I'd appreciate any help or insight...

Thanks,
-Brad

Nov 17 '05 #2

P: n/a
Well, that seems to work globally, for the whole control, but I need to
be able to set different regions on different parts of the control. I
have scroll bars and if I reduce the region to where I want the
checkboxes confined, the scrollbars wont draw because they'll be
outside the region. I think the problem is I can draw my own graphics
fine, but as soon as OnPaint exits, all the scrollbars and checkboxes
draw and I don't have control over their clipping except globally with
Region. Is there a way to tell the child controls when to draw? Then
I could set the region, tell the checkboxes to draw, then increase the
region and tell the scrollbars to draw, then draw my own stuff. Is
that possible? What is the usual way to handle this situation?

Thanks,
-Brad

Tim Wilson UNDERSCORE AT PERIOD wrote:
You should be able to use the "Region" property for this purpose.
http://msdn.microsoft.com/library/de...egiontopic.asp

--
Tim Wilson
.Net Compact Framework MVP


Nov 17 '05 #3

P: n/a
If you know the scrollbars are going to be there then you can take the
scrollbars into consideration when you paint, or size the child controls, by
using the "HorizontalScrollBarHeight" and "VerticalScrollBarWidth"
properties of the "SystemInformation" class.
http://msdn.microsoft.com/library/de...mberstopic.asp

You can assign a different region to each child control if that makes things
easier. If you need a complex region then you can create a "GraphicsPath"
object and then pass this object to one of the constructor overloads for the
"Region" class to create a region using the GraphicsPath.
http://msdn.microsoft.com/library/de...classtopic.asp

I think that you may need to use one of these techniques, or a combination
of both, to achieve what you're trying to do.

--
Tim Wilson
..Net Compact Framework MVP

"BradBrigade" <si********@hotmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Well, that seems to work globally, for the whole control, but I need to
be able to set different regions on different parts of the control. I
have scroll bars and if I reduce the region to where I want the
checkboxes confined, the scrollbars wont draw because they'll be
outside the region. I think the problem is I can draw my own graphics
fine, but as soon as OnPaint exits, all the scrollbars and checkboxes
draw and I don't have control over their clipping except globally with
Region. Is there a way to tell the child controls when to draw? Then
I could set the region, tell the checkboxes to draw, then increase the
region and tell the scrollbars to draw, then draw my own stuff. Is
that possible? What is the usual way to handle this situation?

Thanks,
-Brad

Tim Wilson UNDERSCORE AT PERIOD wrote:
You should be able to use the "Region" property for this purpose.
http://msdn.microsoft.com/library/de...egiontopic.asp
--
Tim Wilson
.Net Compact Framework MVP

Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.