※ 引述《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