//选择不同椭圆对象时触发的事件 private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { foreach (var w in graphicsList) { w.PenColor = Color.Red; } DrawEllipse dw = graphicsList[listBox1.SelectedIndex]; dw.PenColor = Color.Blue; panel1.Refresh(); }
//鼠标按下时触发的事件 private void panel1_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { id++; DrawEllipse w = new DrawEllipse(e.X, e.Y, 1, 1, Color.Red); graphicsList.Add(w); listBox1.Items.Add("椭圆对象:" + id.ToString()); panel1.Refresh(); } }
//鼠标移动时触发的事件 private void panel1_MouseMove(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { if (graphicsList.Count() > 0) { //获得泛型列表的最后一个元素 DrawEllipse w = graphicsList.Last(); int x = w.Rect.X; int y = w.Rect.Y; w.Rect = new Rectangle(x, y, e.X - x, e.Y - y); panel1.Refresh(); } } }