!~~~!C#画图程序出现问题!~~~!
//画笔参数Pen pen = new Pen(Color.Black, 1);
Color color = Color.Black;
float width;
//直线参数
Point startpoint;
Point currentpoint;
bool mousedown = false;
//画图
GraphicsPath gPath = new GraphicsPath();
Graphics gs;
Bitmap bitmap;
private void Form1_Load(object sender, EventArgs e)
{
bitmap = new Bitmap(SystemInformation.PrimaryMonitorMaximizedWindowSize.Width,SystemInformation.PrimaryMonitorMaximizedWindowSize.Height);
gs = Graphics.FromImage(bitmap);
gs.Clear(Color.White);
gs.Dispose();
}
private void trackBar1_ValueChanged(object sender, EventArgs e)
{
width = trackBar1.Value;
}
private void colorPickerButton1_SelectedColorChanged(object sender, EventArgs e)
{
color = colorPickerButton1.SelectedColor;
}
private void panel1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
mousedown = true;
pen = new Pen(color, width);
startpoint = new Point(e.X, e.Y);
}
}
private void panel1_MouseMove(object sender, MouseEventArgs e)
{
if (mousedown && e.Button == MouseButtons.Left)
{
currentpoint = new Point(e.X, e.Y);
Graphics gs = panel1.CreateGraphics();
gs.DrawImage(bitmap, 0, 0);
gs.DrawLine(pen, startpoint, currentpoint);
gs.Dispose();
}
}
private void panel1_MouseUp(object sender, MouseEventArgs e)
{
if (mousedown)
{
gPath.AddLine(startpoint, currentpoint);
Graphics gs = Graphics.FromImage(bitmap);
gs.DrawPath(pen, gPath);
}
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawImage(bitmap, 0, 0);
}
画到第三条先,自动连接第一条和第二条直线的;画第四条直线自动连接第二条和第一条直线的!~
希望大侠帮帮忙,看看出了什么问题!
[[italic] 本帖最后由 68948436 于 2007-12-3 18:40 编辑 [/italic]]