日期:2014-05-18  浏览次数:20851 次

这段代码为什么不能正常绘制
C# code

        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

------解决方案--------------------
下面这个页面或许对你有帮助
http://topic.csdn.net/t/20060325/11/4639197.html
------解决方案--------------------
C# code

    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();
        }
    }