想画那个十分常见的用鼠标拖出来虚线框,
我的panel里原来画了一个几何模型,
如果我在ondraw里面画虚线框的画,不是把原来的模型也重画了一遍吗?
只想单纯的画出一个矩形框,新手,大虾见谅!!!
我的panel里原来画了一个几何模型,
如果我在ondraw里面画虚线框的画,不是把原来的模型也重画了一遍吗?
只想单纯的画出一个矩形框,新手,大虾见谅!!!
解决方案 »
- 函数传参可以宏替换?
- 请问如何取消monthcalendar的翻月事件呢?
- 网上下载了一个第三方库PDFLibNet不能再.net framework4中运行
- .NET Runtime version 2.0.50727.4927 - 执行引擎错误(000007FEF454FA42) (80131506)
- dataGridView绑定数据后,如何设置它不显示数据,让自己重新指定数据
- 急急急,VS2003调用一般处理程序从页面访问得到的不是图片问题??
- 两个页面之间传值问题
- 关于js操作表格的问题
- 将rechtextbox中的数据写入到文件中的换行处理
- 如何安装ADO.net
- datagrid 刷数据的问题(winform下)
- 求一正则表达式,得出下边网页源文件中的所有<li></li>内容,谢谢!
using System.Drawing;定义两个变量
bool MouseIsDow=false;
Rectangle 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 = this.RectangleToScreen(MouseRect);
ControlPaint.DrawReversibleFrame(rect, Color.White, FrameStyle.Dashed);
}private void DrawStart(Point StartPoint)
{
this.Capture = true;
Cursor.Clip = this.RectangleToScreen(this.Bounds);
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;这样就没有重绘控件
using System.Drawing;定义两个变量
bool MouseIsDow=false;
Rectangle 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 = this.RectangleToScreen(MouseRect);
ControlPaint.DrawReversibleFrame(rect, Color.White, FrameStyle.Dashed);
}private void DrawStart(Point StartPoint)
{
this.Capture = true;
Cursor.Clip = this.RectangleToScreen(this.Bounds);
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;这样就没有重绘控件
MouseIsDown
我定义时写错了
MouseIsDow
没问题哦~
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace Probation
{
public partial class frmMain : Form
{
bool MouseIsDown = false;
Rectangle MouseRect = Rectangle.Empty;
public frmMain()
{
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);
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication1
{
public partial class Form1 : Form
{ public Form1()
{
InitializeComponent();
} bool MouseIsDown = false;
Rectangle MouseRect = Rectangle.Empty; private void panel1_MouseUp(object sender, MouseEventArgs e)
{
this.Capture = false;
Cursor.Clip = Rectangle.Empty;
MouseIsDown = false;
DrawRectangle();
MouseRect = Rectangle.Empty;
} private void panel1_MouseMove(object sender, MouseEventArgs e)
{
if (MouseIsDown)
ResizeToRectangle(e.Location);
} private void panel1_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.Red, FrameStyle.Thick);
} private void DrawStart(Point StartPoint)
{
this.Capture = true;
Cursor.Clip = this.RectangleToScreen(this.Bounds);
MouseRect = new Rectangle(StartPoint.X, StartPoint.Y, 0, 0);
} }
}
这个哪错了吗? 真晕...就过家个Panel
如果是加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);
这是设置鼠标筐选时鼠标的移动区域 根据你的需要自己去设置
如果要写Panel 里 就得继承Panel