看板 Programming 關於我們 聯絡資訊
大家好,我自己看書學VC#,剛學兩天 碰到兩個問題,對照程式碼跟書上完全一樣 也沒有偵測到錯誤,可是我的就是不跑,書上光碟範例會跑 不知道是不是PaintEventArgs的問題 因為兩個錯誤都有用到這個函式 我把我的整個專案上傳了 http://rapidshare.de/files/48715036/C.zip.html 底下是我的程式碼,可以請高手指導我一下嗎? 謝謝! 一、這是要讓滑鼠點就會出現圖形的 namespace WindowsFormsApplication1 { public partial class Form1 : Form { Point[] pt = new Point[100]; int pt_index = -1; Image img = Properties.Resources.STBZ055; public Form1() { InitializeComponent(); } private void Form1_MouseDown(object sender, MouseEventArgs e) { if (pt_index < pt.Length) { pt_index++; pt[pt_index] = new Point(e.X, e.Y); } this.Invalidate(); } private void Form1_Paint(object sender, PaintEventArgs e) { for (int i = 0; i <= pt_index; i++) { e.Graphics.DrawImage(img, pt[i].X - img.Width / 2, pt[i].Y - img.Height / 2, img.Width, img.Height); } } } } 二、這是要跑出直線的程式 namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Paint(object sender, PaintEventArgs e) { for (int i = 1; i <= 20; i++) { if (i % 2 == 0) e.Graphics.DrawLine(Pens.Red, i * 20, 30, i * 20, 100); else e.Graphics.DrawLine(Pens.Black, i * 20, 50, i * 20, 100); } } private void Form1_Load(object sender, EventArgs e) { } } } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.219.153.192
karcher:check 一下你的Form1.paint ... 114.25.178.27 11/21 19:37
Piner:怎麼作? 61.219.153.192 11/21 19:47
hotdogee:檢查Form1的paint事件有沒有設handler 118.169.196.7 11/21 20:01
hotdogee:如果Form1_Paint是手動打上去的那8成沒有 118.169.196.7 11/21 20:02
Piner:手打的ㄟ 那我要怎麼設定? 61.219.153.192 11/21 20:06
hotdogee:有很多方法 你可以手打 或是用IDE產生 118.169.196.7 11/21 20:12
Piner:有沒有教學網站或文章呢 sorry我非二類的 61.219.153.192 11/21 20:13
Piner:只有看書學兩天而已 剛起步 61.219.153.192 11/21 20:14
hotdogee:到Form1的屬性視窗 按上方的閃電按鈕切到 118.169.196.7 11/21 20:14
hotdogee:Event模式 找到Paint事件 填入 118.169.196.7 11/21 20:15
hotdogee:Form1_Paint。 或是直接在空白處按兩下 118.169.196.7 11/21 20:16
Piner:啊哈 可以了可以了 哈哈哈 謝謝謝謝!Y 61.219.153.192 11/21 21:00