About override the OnPaint function! 
Author Message
 About override the OnPaint function!

dear Experts:

The class CPanel is inherited from System.Windows.Forms.Panel
and I override the OnPaint function.

I put the instance of the CPanel on a form.

the problem is:
The lines drawed last time by CPanel is not clear when the form is
largening.

Is there some function can auto redraw the control?

//Code

public class CPanel:Panel
 {
  public CPanel()
  {
  }

  protected override void OnPaint(PaintEventArgs e)
  {
   int pX=5,pY=4;
   int I=0;
   Pen _Pen3=new Pen(Color.Gray,1);
   Pen _Pen=new Pen(Color.DimGray,1);
   Pen _Pen2=new Pen(Color.White,1);
   for(I=1;I<=8;I++)
   {
    e.Graphics.DrawLine(_Pen3,new Point(pX,pY),new Point(pX+2,pY));
    pY+=2;
   }
   e.Graphics.DrawLine(_Pen2,new Point(0,0),new Point(this.Width-1,0));
   e.Graphics.DrawLine(_Pen2,new Point(0,0),new Point(0,this.Height-1));
   e.Graphics.DrawLine(_Pen,new Point(0,this.Height-1),new
Point(this.Width-1,this.Height-1));
   e.Graphics.DrawLine(_Pen,new Point(this.Width-1,0),new
Point(this.Width-1,this.Height-1));
   base.OnPaint(e);
  }
 }



Sat, 15 Jan 2005 02:22:06 GMT  
 About override the OnPaint function!
netbugs,

    You will have to handle this yourself.  It's easy though, override the
OnResize method of your class to invalidate the control (causing a repaint)
when the control is resized.

    Hope this helps.

--
               - Nicholas Paldino [.NET MVP]


Quote:
> dear Experts:

> The class CPanel is inherited from System.Windows.Forms.Panel
> and I override the OnPaint function.

> I put the instance of the CPanel on a form.

> the problem is:
> The lines drawed last time by CPanel is not clear when the form is
> largening.

> Is there some function can auto redraw the control?

> //Code

> public class CPanel:Panel
>  {
>   public CPanel()
>   {
>   }

>   protected override void OnPaint(PaintEventArgs e)
>   {
>    int pX=5,pY=4;
>    int I=0;
>    Pen _Pen3=new Pen(Color.Gray,1);
>    Pen _Pen=new Pen(Color.DimGray,1);
>    Pen _Pen2=new Pen(Color.White,1);
>    for(I=1;I<=8;I++)
>    {
>     e.Graphics.DrawLine(_Pen3,new Point(pX,pY),new Point(pX+2,pY));
>     pY+=2;
>    }
>    e.Graphics.DrawLine(_Pen2,new Point(0,0),new Point(this.Width-1,0));
>    e.Graphics.DrawLine(_Pen2,new Point(0,0),new Point(0,this.Height-1));
>    e.Graphics.DrawLine(_Pen,new Point(0,this.Height-1),new
> Point(this.Width-1,this.Height-1));
>    e.Graphics.DrawLine(_Pen,new Point(this.Width-1,0),new
> Point(this.Width-1,this.Height-1));
>    base.OnPaint(e);
>   }
>  }



Sat, 15 Jan 2005 02:25:06 GMT  
 About override the OnPaint function!
It worked!!!
:)
Thanks you very much.


Sat, 15 Jan 2005 02:44:52 GMT  
 About override the OnPaint function!

Quote:
> dear Experts:
> the problem is:
> The lines drawed last time by CPanel is not clear when the form is
> largening.

> Is there some function can auto redraw the control?

Try putting this in your constructor:

this.SetStyle( ControlStyles.ResizeRedraw, true );

--
Arild Fines



Sat, 15 Jan 2005 03:22:49 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. About override the OnPaint function.

2. Override OnPaint in ATL/WTL

3. OnPaint override on CListViewCtrl?

4. CListView - Overriding OnPaint()

5. Overriding OnPaint of CListView

6. OnPaint() override

7. Can we override a control's OnPaint ?

8. CListBox -- Owner Drawn - (override OnPaint) - Need help, please!

9. Overriding the OnPaint method for button controls

10. overriding events (OnPaint, OnClick, etc.)

11. Overriding function and calling the overriden functions

12. how to call OnPaint() from my own function

 

 
Powered by phpBB® Forum Software