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

为什么在Form1_Load函数里绘图没有反应?
[code=C#][/code] private void Form1_Load(object sender, EventArgs e)
  {
  Graphics g = this.CreateGraphics();
  g.SmoothingMode = SmoothingMode.AntiAlias;
  g.FillEllipse(new SolidBrush(Color.Black), new Rectangle(0, 0, 50, 50));
  g.Dispose();
  }
运行后什么都没有。求解释啊。。

------解决方案--------------------
探讨
引用:
一定要在onpaint里吗?我这里创建了Graphics对象,为什么还不行?

应该绘到控件上
Load 在第一次显示窗体前发生。
OnPaint 引发 Paint 事件。 (重写 Control.OnPaint(PaintEventArgs)。)

引发Paint事件,才会重绘控件。