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

huyinhou 2012-03-08 10:24:57

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
...全文
58 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
huyinhou 2012-03-09
  • 打赏
  • 举报
回复
找到了,谢谢大家。
是ResizeRedraw样式的问题。

this.SetStyle(ControlStyles.ResizeRedraw, true);
sofant 2012-03-08
  • 打赏
  • 举报
回复

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();
}
}
xiaxia 2012-03-08
  • 打赏
  • 举报
回复
下面这个页面或许对你有帮助
http://topic.csdn.net/t/20060325/11/4639197.html

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧