color的問題請大家教教謝謝
类里面的:using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
namespace _2011._11._04
{
public class Lines0
{
Point _FirstPoint0 = Point.Empty;
public Point FirstPoint0
{
get { return _FirstPoint0; }
set { _FirstPoint0 = value; }
}
Point _secordPoint0 = Point.Empty;
public Point SecordPoint0
{
get { return _secordPoint0; }
set { _secordPoint0 = value; }
}
}
}
Form1里面的
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace _2011._11._04
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//====== 变量 命名
Graphics g0;
Lines0 currLine0 = null;
List<Lines0> MyLines0 = new List<Lines0>();
private Color abc;
string sun = "";
private void Form1_Load(object sender, EventArgs e)
{
g0 = this.CreateGraphics();
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (currLine0 != null)
{
currLine0.SecordPoint0 = new Point(e.X, e.Y);
this.Invalidate();
currLine0 = new Lines0();
currLine0.SecordPoint0 = new Point(e.X, e.Y);
currLine0.FirstPoint0 = new Point(e.X, e.Y);
MyLines0.Add(currLine0);
}
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
if (currLine0 == null) return;
{
currLine0.SecordPoint0 = new Point(e.X, e.Y);
currLine0 = null;
}
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
currLine0 = new Lines0();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
for (int i = 0; i < MyLines0.Count; i++)
{
if (sun == "")
{
g0.DrawLine(Pens.Black, MyLines0[i].FirstPoint0, MyLines0[i].SecordPoint0);
}
if (sun == "bb")
{
Pen ppen = new Pen(this.abc, 1);
g0.DrawLine(ppen, MyLines0[i].FirstPoint0, MyLines0[i].SecordPoint0);
}
}
}
private void button1_Click(object sender, EventArgs e)
{
sun = "bb";
DialogResult mycolor = colorDialog1.ShowDialog();
if (mycolor == DialogResult.OK)//确定事件响应
{
abc = colorDialog1.Color;
}
if (mycolor == DialogResult.Cancel)//取消事件响应
{
this.abc = Color.Black;
}
}
}
}