C# 为什么新表格是dosen';当快速移动鼠标时,是否不能坚持鼠标移动位置?
我有这个活动:C# 为什么新表格是dosen';当快速移动鼠标时,是否不能坚持鼠标移动位置?,c#,mousecapture,C#,Mousecapture,我有这个活动: protected override void OnMouseDown(MouseEventArgs e) { mOffset = new Point(Width / 2 - e.X, Height / 2 - e.Y); mCurrentPoint = PointToScreen(new Point(e.X + mOffset.X, e.Y + mOffset.Y)); mTargetPoint = mCurrentPoint; mTimer.E
protected override void OnMouseDown(MouseEventArgs e)
{
mOffset = new Point(Width / 2 - e.X, Height / 2 - e.Y);
mCurrentPoint = PointToScreen(new Point(e.X + mOffset.X, e.Y + mOffset.Y));
mTargetPoint = mCurrentPoint;
mTimer.Enabled = true;
}
protected override void OnMouseMove(MouseEventArgs e)
{
mTargetPoint = PointToScreen(new Point(e.X + mOffset.X, e.Y + mOffset.Y));
mTimer.Enabled = true;
}
这次活动:
protected override void OnMouseDown(MouseEventArgs e)
{
mOffset = new Point(Width / 2 - e.X, Height / 2 - e.Y);
mCurrentPoint = PointToScreen(new Point(e.X + mOffset.X, e.Y + mOffset.Y));
mTargetPoint = mCurrentPoint;
mTimer.Enabled = true;
}
protected override void OnMouseMove(MouseEventArgs e)
{
mTargetPoint = PointToScreen(new Point(e.X + mOffset.X, e.Y + mOffset.Y));
mTimer.Enabled = true;
}
如果我只是快速移动鼠标,我就失去了对正在移动的窗体的关注,窗体只在鼠标移动时留在原地
但是,如果我点击鼠标下键,然后移动鼠标,快速的形式是在焦点的所有方式
因此,我尝试将OnMouseDown
事件中的两行内容复制到OnMouseMove
事件中:
mOffset = new Point(Width / 2 - e.X, Height / 2 - e.Y);
mTargetPoint = mCurrentPoint;
但一旦我把这两行移到移动事件中,什么都不会发生。无论我做什么,表格都不动
如果需要,这是完整的表单代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.IO;
using System.Drawing.Imaging;
namespace Magnifier20070401
{
public partial class MagnifierForm : Form
{
public MagnifierForm()//Configuration configuration, Point startPoint)
{
InitializeComponent();
//--- My Init ---
//mConfiguration = configuration;
FormBorderStyle = FormBorderStyle.None;
ShowInTaskbar = false;//mConfiguration.ShowInTaskbar;
TopMost = true;//mConfiguration.TopMostWindow;
Width = 150;// mConfiguration.MagnifierWidth;
Height = 150;// mConfiguration.MagnifierHeight;
// Make the window (the form) circular
GraphicsPath gp = new GraphicsPath();
gp.AddEllipse(ClientRectangle);
Region = new Region(gp);
mImageMagnifier = ScreenVideoRecorder.Properties.Resources.magnifierGlass;
mTimer = new Timer();
mTimer.Enabled = true;
mTimer.Interval = 20;
mTimer.Tick += new EventHandler(HandleTimer);
mScreenImage = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
Screen.PrimaryScreen.Bounds.Height);
mStartPoint = new Point(500, 500);// startPoint;
mTargetPoint = new Point(500, 500); // startPoint;
/*if (mConfiguration.ShowInTaskbar)
ShowInTaskbar = true;
else
ShowInTaskbar = false;*/
}
protected override void OnShown(EventArgs e)
{
RepositionAndShow();
}
private delegate void RepositionAndShowDelegate();
private void RepositionAndShow()
{
if (InvokeRequired)
{
Invoke(new RepositionAndShowDelegate(RepositionAndShow));
}
else
{
// Capture the screen image now!
Graphics g = Graphics.FromImage(mScreenImage);
g.CopyFromScreen(0, 0, 0, 0, new Size(mScreenImage.Width, mScreenImage.Height));
g.Dispose();
//if (mConfiguration.HideMouseCursor)
// Cursor.Hide();
//else
Cursor = Cursors.Cross;
Capture = true;
/*if (mConfiguration.RememberLastPoint)
{
mCurrentPoint = mLastMagnifierPosition;
Cursor.Position = mLastMagnifierPosition;
Left = (int)mCurrentPoint.X - Width / 2;
Top = (int)mCurrentPoint.Y - Height / 2;
}
else
{*/
mCurrentPoint = Cursor.Position;
//}
Show();
}
}
void HandleTimer(object sender, EventArgs e)
{
float dx = /*mConfiguration.SpeedFactor*/ (float)0.35 * (mTargetPoint.X - mCurrentPoint.X);
float dy = /*mConfiguration.SpeedFactor*/ (float)0.35 * (mTargetPoint.Y - mCurrentPoint.Y);
if (mFirstTime)
{
mFirstTime = false;
mCurrentPoint.X = mTargetPoint.X;
mCurrentPoint.Y = mTargetPoint.Y;
Left = (int)mCurrentPoint.X - Width / 2;
Top = (int)mCurrentPoint.Y - Height / 2;
return;
}
mCurrentPoint.X += dx;
mCurrentPoint.Y += dy;
if (Math.Abs(dx) < 1 && Math.Abs(dy) < 1)
{
mTimer.Enabled = false;
}
else
{
// Update location
Left = (int)mCurrentPoint.X - Width / 2;
Top = (int)mCurrentPoint.Y - Height / 2;
mLastMagnifierPosition = new Point((int)mCurrentPoint.X, (int)mCurrentPoint.Y);
}
Refresh();
}
protected override void OnMouseDown(MouseEventArgs e)
{
mOffset = new Point(Width / 2 - e.X, Height / 2 - e.Y);
mCurrentPoint = PointToScreen(new Point(e.X + mOffset.X, e.Y + mOffset.Y));
mTargetPoint = mCurrentPoint;
mTimer.Enabled = true;
}
protected override void OnMouseUp(MouseEventArgs e)
{
//if (mConfiguration.CloseOnMouseUp)
//{
/* Close();
mScreenImage.Dispose();
//}
Cursor.Show();
Cursor.Position = mStartPoint; */
}
protected override void OnMouseMove(MouseEventArgs e)
{
//if (e.Button == MouseButtons.Left)
//{
mOffset = new Point(Width / 2 - e.X, Height / 2 - e.Y);
mTargetPoint = PointToScreen(new Point(e.X + mOffset.X, e.Y + mOffset.Y));
//mTargetPoint = mCurrentPoint;
mTimer.Enabled = true;
//}
}
protected override void OnPaintBackground(PaintEventArgs e)
{
/*if (mConfiguration.DoubleBuffered)
{
// Do not paint background (required for double buffering)!
}
else
{
base.OnPaintBackground(e);
}*/
base.OnPaintBackground(e);
}
protected override void OnPaint(PaintEventArgs e)
{
if (mBufferImage == null)
{
mBufferImage = new Bitmap(Width, Height);
}
Graphics bufferGrf = Graphics.FromImage(mBufferImage);
Graphics g;
/*if (mConfiguration.DoubleBuffered)
{
g = bufferGrf;
}
else
{*/
g = e.Graphics;
//}
if (mScreenImage != null)
{
Rectangle dest = new Rectangle(0, 0, Width, Height);
int w = (int)(Width / 3.0);//mConfiguration.ZoomFactor);
int h = (int)(Height / 3.0);//mConfiguration.ZoomFactor);
int x = Left - w / 2 + Width / 2;
int y = Top - h / 2 + Height / 2;
g.DrawImage(
mScreenImage,
dest,
x, y,
w, h,
GraphicsUnit.Pixel);
}
if (mImageMagnifier != null)
{
g.DrawImage(mImageMagnifier, 0, 0, Width, Height);
}
//if (mConfiguration.DoubleBuffered)
//{
e.Graphics.DrawImage(mBufferImage, 0, 0, Width, Height);
//}
}
//--- Data Members ---
#region Data Members
private Timer mTimer;
private Configuration mConfiguration;
private Image mImageMagnifier;
private Image mBufferImage = null;
private Image mScreenImage = null;
private Point mStartPoint;
private PointF mTargetPoint;
private PointF mCurrentPoint;
private Point mOffset;
private bool mFirstTime = true;
private static Point mLastMagnifierPosition = Cursor.Position;
#endregion
private void MagnifierForm_KeyDown(object sender, KeyEventArgs e)
{
if (e.Control && e.KeyCode.ToString() == "M")
{
this.Close();
}
}
}
}
使用系统;
使用System.Collections.Generic;
使用系统组件模型;
使用系统数据;
使用系统图;
使用系统文本;
使用System.Windows.Forms;
使用System.Drawing.Drawing2D;
使用System.IO;
使用系统、绘图、成像;
名称空间放大镜20070401
{
公共部分类放大镜窗体:窗体
{
public MagnifierForm()//配置,点开始点)
{
初始化组件();
//---我的名字---
//mConfiguration=配置;
FormBorderStyle=FormBorderStyle.无;
ShowInTaskbar=false;//mConfiguration.ShowInTaskbar;
TopMost=true;//mConfiguration.TopMostWindow;
宽度=150;//mConfiguration.MagnifierWidth;
高度=150;//mConfiguration.放大镜高度;
//把窗户(窗体)做成圆形
GraphicsPath gp=新的GraphicsPath();
加法器总成(ClientRectangle);
地区=新地区(gp);
mimage放大镜=ScreenVideoRecorder.Properties.Resources.放大镜;
mTimer=新计时器();
mTimer.Enabled=true;
平均时间间隔=20;
mTimer.Tick+=新的EventHandler(HandleTime);
mScreenImage=新位图(Screen.PrimaryScreen.Bounds.Width,
屏幕。主屏幕。边界。高度);
mStartPoint=新点(500500);//起始点;
mTargetPoint=新点(500500);//起始点;
/*if(mConfiguration.ShowInTaskbar)
ShowInTaskbar=true;
其他的
ShowInTaskbar=false*/
}
显示时受保护的覆盖无效(事件参数e)
{
重新定位并显示();
}
私有委托和ShowDelegate();
私有void和show()
{
如果(需要调用)
{
调用(新的重新定位和显示委托(重新定位和显示));
}
其他的
{
//现在捕捉屏幕图像!
Graphics g=Graphics.FromImage(mScreenImage);
g、 CopyFromScreen(0,0,0,0,新大小(mScreenImage.Width,mScreenImage.Height));
g、 处置();
//if(mConfiguration.HideMouseCursor)
//Cursor.Hide();
//否则
游标=游标。十字;
捕获=真;
/*if(mConfiguration.RememberLastPoint)
{
mCurrentPoint=MLAST放大镜位置;
Cursor.Position=MLAST放大镜位置;
左=(int)mCurrentPoint.X-宽度/2;
顶部=(int)mCurrentPoint.Y-高度/2;
}
其他的
{*/
mCurrentPoint=光标位置;
//}
Show();
}
}
void HandleTimer(对象发送方,事件参数e)
{
float dx=/*mConfiguration.SpeedFactor*/(float)0.35*(mTargetPoint.X-mCurrentPoint.X);
float dy=/*mConfiguration.SpeedFactor*/(float)0.35*(mTargetPoint.Y-mccurrentpoint.Y);
如果(第一次)
{
mFirstTime=false;
mCurrentPoint.X=mTargetPoint.X;
mCurrentPoint.Y=mTargetPoint.Y;
左=(int)mCurrentPoint.X-宽度/2;
顶部=(int)mCurrentPoint.Y-高度/2;
返回;
}
mCurrentPoint.X+=dx;
mCurrentPoint.Y+=dy;
if(数学Abs(dx)<1&&Math.Abs(dy)<1)
{
mTimer.Enabled=false;
}
其他的
{
//更新位置
左=(int)mCurrentPoint.X-宽度/2;
顶部=(int)mCurrentPoint.Y-高度/2;
MLAST放大镜位置=新点((int)mCurrentPoint.X,(int)mCurrentPoint.Y);
}
刷新();
}
MouseEventArgs e上的受保护覆盖无效(MouseEventArgs e)
{
mOffset=新点(宽度/2-e.X,高度/2-e.Y);
mCurrentPoint=指向屏幕的点(新点(e.X+mOffset.X,e.Y+mOffset.Y));
mTargetPoint=mCurrentPoint;
mTimer.Enabled=true;
}
MouseUp上的受保护覆盖无效(MouseEventArgs e)
{
//if(mConfiguration.CloseOnMouseUp)
//{
/*Close();
mScreenImage.Dispose();
//}
Cursor.Show();
Cursor.Position=mStartPoint;*/
}
MouseMove上的受保护覆盖无效(MouseEventArgs e)
{
//if(e.Button==MouseButtons.Left)
//{
mOffset=新点(宽度/2-e.X,高度/2-e.Y);
mTargetPoint=PointToScreen(新点(e.X+mOffset.X,e.Y+mOffset.Y));
//mTargetPoint=mCurrentPoint;
mTimer.Enabled=true;
//}
}
PaintBackground上受保护的覆盖无效(PaintEventArgs e)
{
/*if(mConfiguration.DoubleBuffered)
{
//D