首页 > 代码库 > (转)在 ListViewItem 上拖动进行框选
(转)在 ListViewItem 上拖动进行框选
public partial class Form1 : Form{ private bool IsMouseDown = false; Rectangle MouseRect = Rectangle.Empty; public Form1() { InitializeComponent(); } private void listView1_MouseDown(object sender, MouseEventArgs e) { IsMouseDown = true; DrawStart(e.Location); } private void listView1_MouseMove(object sender, MouseEventArgs e) { if (IsMouseDown) { ResizeToRectangle(e.Location); ListViewItem item = listView1.HitTest(e.X, e.Y).Item; if (item != null) { item.Selected = true; } foreach (ListViewItem listViewItem in listView1.SelectedItems) { if ((listViewItem.Bounds.Top > MouseRect.Top && listViewItem.Bounds.Bottom > MouseRect.Top) || (listViewItem.Bounds.Bottom < MouseRect.Bottom && listViewItem.Bounds.Top < MouseRect.Bottom)) { listViewItem.Selected = false; } } } } private void listView1_MouseUp(object sender, MouseEventArgs e) { this.Capture = false; Cursor.Clip = Rectangle.Empty; IsMouseDown = false; DrawRectangle(); MouseRect = Rectangle.Empty; } private void ResizeToRectangle(Point p) { DrawRectangle(); MouseRect.Width = p.X - MouseRect.Left; MouseRect.Height = p.Y - MouseRect.Top; DrawRectangle(); } private void DrawRectangle() { Rectangle rect = listView1.RectangleToScreen(MouseRect); ControlPaint.DrawReversibleFrame(rect, Color.White, FrameStyle.Dashed); } private void DrawStart(Point StartPoint) { this.Capture = true; Cursor.Clip = listView1.RectangleToScreen(new Rectangle(0, 0, ClientSize.Width, ClientSize.Height)); MouseRect = new Rectangle(StartPoint.X, StartPoint.Y, 0, 0); } }
转自: http://social.msdn.microsoft.com/Forums/silverlight/zh-CN/5685ef2c-7cfa-4f03-822c-4992bf6bce1c/-listviewitem-?forum=visualcshartzhchs
(转)在 ListViewItem 上拖动进行框选
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。