[問題] C#程式碼一樣 自己的就是不跑(已解決)
大家好,我自己看書學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
→
11/21 19:37, , 1F
11/21 19:37, 1F
→
11/21 19:47, , 2F
11/21 19:47, 2F
→
11/21 20:01, , 3F
11/21 20:01, 3F
→
11/21 20:02, , 4F
11/21 20:02, 4F
→
11/21 20:06, , 5F
11/21 20:06, 5F
→
11/21 20:12, , 6F
11/21 20:12, 6F
→
11/21 20:13, , 7F
11/21 20:13, 7F
→
11/21 20:14, , 8F
11/21 20:14, 8F
→
11/21 20:14, , 9F
11/21 20:14, 9F
→
11/21 20:15, , 10F
11/21 20:15, 10F
→
11/21 20:16, , 11F
11/21 20:16, 11F
→
11/21 21:00, , 12F
11/21 21:00, 12F