c# winform 用鼠标画拉出来的虚线框,鼠标框选边框效果
来源:互联网 发布:阿里云香港主机连不上 编辑:程序博客网 时间:2024/04/28 13:40
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace AllTest
{
public partial class Form11 : Form
{
bool MouseIsDown = false;
Rectangle MouseRect = Rectangle.Empty;
public Form11()
{
InitializeComponent();
this.MouseDown += new MouseEventHandler(frmMain_MouseDown);
this.MouseMove += new MouseEventHandler(frmMain_MouseMove);
this.MouseUp += new MouseEventHandler(frmMain_MouseUp);
}
void frmMain_MouseUp(object sender, MouseEventArgs e)
{
this.Capture = false;
Cursor.Clip = Rectangle.Empty;
MouseIsDown = false;
DrawRectangle();
MouseRect = Rectangle.Empty;
}
void frmMain_MouseMove(object sender, MouseEventArgs e)
{
if (MouseIsDown)
ResizeToRectangle(e.Location);
}
void frmMain_MouseDown(object sender, MouseEventArgs e)
{
MouseIsDown = true;
DrawStart(e.Location);
}
private void ResizeToRectangle(Point p)
{
DrawRectangle();
MouseRect.Width = p.X - MouseRect.Left;
MouseRect.Height = p.Y - MouseRect.Top;
DrawRectangle();
}
private void DrawRectangle()
{
Rectangle rect = this.RectangleToScreen(MouseRect);
ControlPaint.DrawReversibleFrame(rect, Color.White, FrameStyle.Dashed);
}
private void DrawStart(Point StartPoint)
{
this.Capture = true;
Cursor.Clip = this.RectangleToScreen(new Rectangle(0, 0, ClientSize.Width, ClientSize.Height));
MouseRect = new Rectangle(StartPoint.X, StartPoint.Y, 0, 0);
}
}
}
在鼠标按下事件里写(一定是鼠标按下事件MouseDown 因为我的参数e是鼠标数据对象
(不过你也可以传坐标))
MouseIsDown = true;
DrawStart(e.Location);
在鼠标移动(MouseMove)事件里写
if (MouseIsDown)
ResizeToRectangle(e.Location);
在鼠标释放(MouseUp)事件里写
this.Capture = false;
Cursor.Clip = Rectangle.Empty;
MouseIsDown = false;
DrawRectangle();
MouseRect = Rectangle.Empty;
这样不会覆盖原来的控件,不会重绘控件
如果是加Panel的话
把DrawStart()方法里的Cursor.Clip = this.RectangleToScreen(this.Bounds);
改为Cursor.Clip = this.RectangleToScreen(this.panel1.ClientRectangle));
this.Capture = true;改为 this.panel1.Capture = true;
MouseUp里的 this.Capture = false;改为
this.panel1.Capture = false;
这是设置鼠标筐选时鼠标的移动区域 和控件对鼠标的捕获
Cursor.Clip = this.RectangleToScreen(this.Bounds);
这是设置鼠标筐选时鼠标的移动区域 根据你的需要自己去设置
转帖地址: http://heisetoufa.javaeye.com/blog/380977
- c# winform 用鼠标画拉出来的虚线框,鼠标框选边框效果
- c# winform 用鼠标画拉出来的虚线框,鼠标框选边框效果
- C#,winform,gdi+,简单实现鼠标拉出虚线框,适合新手
- C# Winform 窗体用鼠标拖出虚线框....并且虚线框区域里的所有控件选中
- winform 中实现鼠标框选效果 c#
- 去掉鼠标点击后的虚线边框
- 【winform】鼠标拖动时显示虚线框,减少窗体绘制
- C# 鼠标拖动WinForm无边框窗口
- C# winform 无边框窗体鼠标点击移动事件
- C# winform 无边框窗体鼠标点击移动事件
- C#用鼠标在控件上绘制虚线框,并且获取矩形。
- 去除鼠标点击链接时周围的虚线框
- 链接效果:鼠标放上去显示虚线的下划线
- c# 鼠标移动带边框的pictureBox
- C# 用鼠标拖动无边框窗体
- css设置表格的边框为实线还是虚线,+鼠标悬停显示提示字
- CSS实现鼠标悬停图片时的边框变色效果
- C# WinForm 显示 隐藏 鼠标
- 关于指针与数组的一点感悟
- DB2体系结构
- .NET页面事件执行顺序
- Oracle 11g release 2 (11.2.0.1.0) on Fedora 11
- Java --Annotation 浅析2
- c# winform 用鼠标画拉出来的虚线框,鼠标框选边框效果
- ScrollBar 垂直和水平滚动条的样式
- 放弃某种幸福
- Hyperion System 9 BI常用报表脚本
- 测试人员的发展——个人感觉不错
- PHP开发文件系统实例讲解
- 原始套接字透析之前言
- SQL Server中各数据类型尺寸(Byte)
- Thinkpad电源管理器(Power Manager)无法新建方案解决方法