Clip a child control

B

BradBrigade

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
 
B

BradBrigade

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
 
T

Tim Wilson

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/d...windowsformssysteminformationmemberstopic.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/d...temdrawingdrawing2dgraphicspathclasstopic.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 said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top