Windows Develop Bookmark and Share   
 index > Windows Forms General > Painting Multiple child controls
 

Painting Multiple child controls

Hi,
I'm developing a class derived from Panel Control. It's Transparent, moveable and resizeable. When moving or resizing (onMouseMove event)it draws a Temperory rectangle over the parent control.I
Adding a single control to a form from this class isn't a problem. But when I add multiple controls on a form I have a problem. IfI move a controlthe othersthat areadded laterare not painted.Let's say I have 3 controls If I move the third one everything is normal. If I move the second one the third doesn't paint during movement. If I move the first one the second and third don't paint..After the movement everything comes back.
I think the problem is my later added controls doesn't receive painting calls. I wonder is there a hierarchy according to adding order of controls.

Thanksadvance.

aliassce  Tuesday, April 14, 2009 12:01 PM
Transparency in Windows is faked by drawing the foreground of the container window as the background of the child control. That works just fine for single controls but falls apart when controls overlap each other, stacking effects don't work. Check this thread for a completely different approach. Follow the link in that post to get the important code.
Hans Passant.
nobugz  Tuesday, April 14, 2009 12:26 PM

Thanks for comment.
But actually my problem is not just transparency. While a control is drawing a rectangle on parent form another controls that are added after this are not painted.

My code looks like this

public class MyControl : Panel

{

public MyControl()

{
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
SetStyle(ControlStyles.Opaque, true);
this.SetStyle( ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint ,true);
}

protected override void OnPaint(PaintEventArgs e)

{
// Draw some graphics on this object
// Graphics g= e.Graphics
// ...................

if (IsSMoving)
{
Graphics g2 = this.Parent.CreateGraphics();

// g2.DrawRectangle(); Here we draw a temporary rectangle on parent (Form)
this.Parent.Invoke();
}
base.OnPaint(e);

}

}
}

____________________________

On a form I add some objects from this class. But if a control is moving the ones added later are not shown until it stops moving.

aliassce  Tuesday, April 14, 2009 3:23 PM

You can use google to search for other answers

Custom Search

More Threads

• Input Method Editor (IME) Isn't Working!
• the Xp visual theam problem
• Display animated GIF in PictureBox
• File Selection
• cross Thread control accessbility
• login with function, how to enables menuitems in the parent form?
• Hide() not working when system is busy
• OEM keycodes
• RichTextBox
• Submitting XML to ASP.net