學VC#碰到兩個問題,對照程式碼跟書上完全一樣
也沒有偵測到錯誤,可是我的就是不跑,書上光碟範例會跑
我把我的整個專案上傳了
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)
{
}
}
}