作者leicheong (睡魔)
看板C_Sharp
标题Re: [问题] 用Graphics却出不来
时间Sat Nov 28 12:40:15 2009
※ 引述《hirabbitt (兔子)》之铭言:
: 有个新问题...
: 我在FORM1_LOAD中写
: Pen p = new Pen(c1, 1);
: g2.DrawEllipse(p, 0, 0, 16, 16);
: g3.DrawEllipse(p, 0, 0, 16, 16);
: 没有用
: 在FORM_ACTIVED写也没用
: 而在FORM_SHOWN则是会一闪而过
: 确定都有用事件关联过去了
: 请问如果我要在FORM一开始就执行
: 怎样写才对?
除非你有方法取代WM_ERASEBKGND的event handler, 否则你画上去的
内容会在WM_PAINT被Windows本身cache的内容覆盖的.
在MSDN Documentation中也有提到, 你只能在PAINT event中使用
Form的Graphics object.
In Visual Basic 2008, graphics methods should only be called from the Paint
event procedure, or in the case of some owner-drawn controls, from the
various Draw event procedures (DrawItem, DrawSubItem, etc.). The AutoRedraw
property is no longer supported and is not necessary because the Paint and
Draw events automatically persist graphics.
那麽以下是sample code...
private void Form1_Paint(object sender, PaintEventArgs e)
{
Pen p = new Pen(Color.Red, 1);
e.Graphics.DrawEllipse(p, 0, 0, 16, 16);
e.Graphics.DrawEllipse(p, 0, 0, 16, 16);
}
--
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 203.218.225.186