请问OnMouseMove(MouseEventArgs e) 怎样在整个桌面起作用?

atlone 2003-10-20 11:57:08
因为以下的代码,所以mouse只能在form内移动才可以产生效果,出了form外移动,就不能产生效果,请问怎样可以让mouse在form外移动也可以产生效果? 先谢谢了.


public class FormMain: Form
{

.......

protected override void OnMouseMove(MouseEventArgs e)
{
.........
}

.....
}
...全文
87 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhoutiance 2003-10-21
  • 打赏
  • 举报
回复
关注中……
HNU 2003-10-21
  • 打赏
  • 举报
回复
你要什么效果?
出了FORM 能做什么?画图?
我猜测要获取桌面DC
HNU 2003-10-21
  • 打赏
  • 举报
回复

楼主给我分?实在是不好意思!

守信。
CodeSpirit 2003-10-21
  • 打赏
  • 举报
回复
以前用delphi写的话要用hook,我不知道现在.net里面有没有什么相关的api可以实现
using System; using System.Drawing; using System.Windows.Forms; namespace ClipImage { public partial class FormImage : Form { #region private Point position; private Rectangle clip; #endregion public FormImage() { #region InitializeComponent(); this.TopMost = true; // 前端显示。 this.ShowInTaskbar = false; // 在 Windows 任务栏中隐藏窗体。 this.DoubleBuffered = true; // 双缓冲绘制图形。 this.FormBorderStyle = FormBorderStyle.None; // 窗体无边框。 this.Bounds = Screen.GetBounds(this); // 获取显示器的桌面区域。 this.TransparencyKey = this.BackColor; // 窗体背景透明化。 NotifyIcon notify = new NotifyIcon(); notify.Visible = true; // 图标在任务栏的通知区域中可见。 notify.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath); // 启动程序图标。 notify.Text = AppDomain.CurrentDomain.FriendlyName; // 启动程序名称。 notify.MouseClick += new MouseEventHandler(notify_MouseClick); #endregion } #region OnMouseDown protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); switch (e.Button) { case MouseButtons.Left: position = e.Location; // 设置起始位置。 break; case MouseButtons.Right: if (clip.Width > 1 && clip.Height > 1) { clip.Offset(1, 1); // 平移。 using (Bitmap bmp = new Bitmap(--clip.Width, --clip.Height)) using (Graphics g = Graphics.FromImage(bmp)) { g.CopyFromScreen(clip.Location, Point.Empty, clip.Size); // 截图。 bmp.Save("Image.png", bmp.RawFormat); // 保存图片。 Clipboard.SetImage(bmp); // 图片存储到剪贴板中。 } System.Diagnostics.Process.Start("mspaint.exe", "Image.png"); // 用画图打开图片。 } clip = Rectangle.Empty; BackgroundImage.Dispose(); BackgroundImage = null; break; } } #endregion #region OnMouseMove protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); if (e.Button == MouseButtons.Left) { clip.X = Math.Min(position.X, e.X); clip.Y = Math.Min(position.Y, e.Y); clip.Width = Math.Abs(position.X - e.X); clip.Height = Math.Abs(position.Y - e.Y); this.Refresh(); // 立即重绘图形。 } } #endregion #region OnPaint protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); e.Graphics.DrawRectangle(Pens.Red, clip); e.Dispose(); } #endregion #region NotifyIcon private void notify_MouseClick(object sender, MouseEventArgs e) { switch (e.Button) { case MouseButtons.Left: this.BackgroundImage = new Bitmap(this.Width, this.Height); using (Graphics g = Graphics.FromImage(this.BackgroundImage)) { g.CopyFromScreen(Point.Empty, Point.Empty, this.Size); } this.Activate(); // 激活窗体并给予它焦点。 break; case MouseButtons.Right: (sender as NotifyIcon).Dispose(); Application.Exit(); break; } } #endregion } }

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧