C# 选择画好的其中一根线并删除的问题!帮顶给分!谢谢! C# winform中用DrawLine画了好几条线,怎么选取画好的其中一根线然后按del键删除它,谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace WindowsApplication11{ class Line { public Point P1, P2; public Color Color; public Line(Point P1, Point P2, Color Color) { this.P1 = P1; this.P2 = P2; this.Color = Color; } } public partial class Form1 : Form { Bitmap OrgBmp = new Bitmap(500, 500); List<Line> Lines = new List<Line>(); PictureBox PB = new PictureBox(); Line SelectedLine = null; public Form1() { InitializeComponent(); this.Controls.Clear(); this.AutoSize = true; this.KeyPreview = true; this.KeyDown += new KeyEventHandler(Form1_KeyDown); PB.Size = OrgBmp.Size; PB.Parent = this; PB.Image = OrgBmp; Lines.Add(new Line(new Point(0, 0), new Point(100, 100), Color.Red)); Lines.Add(new Line(new Point(20, 30), new Point(450, 200), Color.Green)); Lines.Add(new Line(new Point(300, 400), new Point(60, 300), Color.Blue)); RefreshImage(); SelectedLine = Lines[1]; // 删除绿线 } void Form1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Delete && SelectedLine != null) { Lines.Remove(SelectedLine); RefreshImage(); } } void RefreshImage() { Bitmap CacheBmp = new Bitmap(OrgBmp); Graphics G = Graphics.FromImage(CacheBmp); foreach (Line L in Lines) G.DrawLine(new Pen(new SolidBrush(L.Color)), L.P1, L.P2); G.Dispose(); PB.Image = CacheBmp; } }} 其实你最主要的问题是pick问题(就是是不是选中的问题)就是将先选中的问题楼上的已经把选中的给删除了,你可以写一个pick()方法解决如果有疑问可以加qq 282231501 注明: 图形 blog.csdn.net/dunao参照V1.0.0.5的那版本的(VS2008开发) 至于选中问题,比较麻烦,如果要鼠标直接可选中,可以试试套用直线的两点式公式,不过公式要变换形式为(y-y1)/(y2-y1)-(x-x1)/(x2-x1)<误差值的形式,不过细节处理起来还是蛮麻烦的 .net 里面如何获得 url 跳转后的真实地址。 动态创建button控件 click事件不能执行 如何截取一个数据包并且分析数据包和使用的协议 在网页中读取文件 如何访问远程的ACCESS数据库? C# linq 过滤数据 c# Excel 2003 插件问题 1.cs(4,17): error CS1002: 应输入 ; 急救 想学ASP。NET + C# + sql server方面的东西 推荐几本电子书 下载! 求助!如何用c#把google map写进去 获取sql server数据库中指定表的创建该表的SQL语句
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication11
{
class Line
{
public Point P1, P2;
public Color Color; public Line(Point P1, Point P2, Color Color)
{
this.P1 = P1;
this.P2 = P2;
this.Color = Color;
}
} public partial class Form1 : Form
{
Bitmap OrgBmp = new Bitmap(500, 500);
List<Line> Lines = new List<Line>();
PictureBox PB = new PictureBox();
Line SelectedLine = null; public Form1()
{
InitializeComponent(); this.Controls.Clear();
this.AutoSize = true;
this.KeyPreview = true;
this.KeyDown += new KeyEventHandler(Form1_KeyDown); PB.Size = OrgBmp.Size;
PB.Parent = this;
PB.Image = OrgBmp; Lines.Add(new Line(new Point(0, 0), new Point(100, 100), Color.Red));
Lines.Add(new Line(new Point(20, 30), new Point(450, 200), Color.Green));
Lines.Add(new Line(new Point(300, 400), new Point(60, 300), Color.Blue)); RefreshImage(); SelectedLine = Lines[1]; // 删除绿线
} void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Delete && SelectedLine != null)
{
Lines.Remove(SelectedLine);
RefreshImage();
}
} void RefreshImage()
{
Bitmap CacheBmp = new Bitmap(OrgBmp);
Graphics G = Graphics.FromImage(CacheBmp);
foreach (Line L in Lines)
G.DrawLine(new Pen(new SolidBrush(L.Color)), L.P1, L.P2);
G.Dispose();
PB.Image = CacheBmp;
}
}
}
就是将先选中的问题
楼上的已经把选中的给删除了,你可以写一个pick()方法解决
如果有疑问可以加qq 282231501 注明: 图形
参照V1.0.0.5的那版本的(VS2008开发)