Problem with custom Panel class
- From: "TT \(Tom Tempelaere\)" </\/_0_$P@/\/\titi____AThotmailD.Tcom/\/\@P$_0_/\/>
- Date: Fri, 06 May 2005 10:13:40 GMT
Hi,
I'm extending the Panel control to allow selection of controls on the Panel
(comparable to selecting icons on the desktop). The problem is that the
selection rectangle is drawn behind the controls on the Panel. What should I
do to have the rectangle drawn in front of the controls on the Panel?
<code>
public class SelectionPanel : Panel
{
private bool isMouseDown = false;
private Point dragFromLocation = new Point( );
private Point dragToLocation = new Point( );
public SelectionPanel( )
{
InitializeComponent( );
}
protected override void OnPaint( PaintEventArgs pe )
{
base.OnPaint( pe );
if( isMouseDown )
{
int x = Math.Min( dragFromLocation.X, dragToLocation.X );
int y = Math.Min( dragFromLocation.Y, dragToLocation.Y );
int width = Math.Abs( dragFromLocation.X - dragToLocation.X );
int height = Math.Abs( dragFromLocation.Y - dragToLocation.Y );
Rectangle rectangle = new Rectangle( x, y, width, height );
ControlPaint.DrawFocusRectangle( pe.Graphics, rectangle );
}
}
private void OnMouseDown(object sender, MouseEventArgs e)
{
isMouseDown = true;
dragFromLocation = new Point( e.X, e.Y );
dragToLocation = dragFromLocation;
}
private void OnMouseUp(object sender, MouseEventArgs e)
{
isMouseDown = false;
Invalidate( );
}
private void OnMouseMove(object sender, MouseEventArgs e)
{
if( isMouseDown )
{
dragToLocation = new Point( e.X, e.Y );
Invalidate( );
}
}
private void InitializeComponent( )
{
this.MouseUp += new System.Windows.Forms.MouseEventHandler(
this.OnMouseUp );
this.MouseMove += new System.Windows.Forms.MouseEventHandler(
this.OnMouseMove );
this.MouseDown += new System.Windows.Forms.MouseEventHandler(
this.OnMouseDown );
}
}
</code>
Kind regards,
Tom Tempelaere.
.
- Follow-Ups:
- Re: Problem with custom Panel class
- From: Bob Powell [MVP]
- Re: Problem with custom Panel class
- Prev by Date: RE: Custom ComboBox with DataSource
- Next by Date: Re: Allow nulls in the DateTimePicker control
- Previous by thread: Property grid and class member display
- Next by thread: Re: Problem with custom Panel class
- Index(es):
Relevant Pages
|