protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Graphics grfx = e.Graphics;
            Rectangle rect = ClientRectangle;
            rect.Inflate(new Size(-100, -100));
            grfx.DrawRectangle(new Pen(Color.Black), rect);
        }
一个简单的windows窗体应用程序,只重载了Form的OnPaint事件,可这段代码在窗体大小改变的时候不能正常工作。
哪位达人能告诉为什么?
晕乎了,谢谢~~   VS 2010

解决方案 »

  1.   

    下面这个页面或许对你有帮助
    http://topic.csdn.net/t/20060325/11/4639197.html
      

  2.   


        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();            this.DoubleBuffered = true;
            }        protected override void OnPaint(PaintEventArgs e)
            {
                base.OnPaint(e);            Rectangle rect = this.ClientRectangle;
                rect.Inflate(-100, -100);
                e.Graphics.DrawRectangle(Pens.Black, rect);
            }        protected override void OnSizeChanged(EventArgs e)
            {
                base.OnSizeChanged(e);
                this.Invalidate();
            }
        }
      

  3.   

    找到了,谢谢大家。
    是ResizeRedraw样式的问题。this.SetStyle(ControlStyles.ResizeRedraw, true);