为什么仅在 MouseDown 事件中单击鼠标左键时才会触发 MouseMove 事件?

发布于 2024-12-19 22:34:45 字数 1168 浏览 2 评论 0原文

要么我不完全理解事件是如何运作的,要么Delphi Prism已经疯了!

我有一个 winform、mousedown 事件和 mousemove 事件。每当我仅单击鼠标左键时,MouseDown 事件就会按预期触发,但 MouseMove 事件也会在不应该触发的情况下立即触发。

这是我的 winform 设计器的一段代码,其中方法被分配给事件。

  self.ClientSize := new System.Drawing.Size(751, 502);
  self.KeyPreview := true;
  self.Name := 'Maker';
  self.Text := 'Window Maker';
  self.Load += new System.EventHandler(@self.Maker_Load);
  self.FormClosing += new System.Windows.Forms.FormClosingEventHandler(@self.Maker_FormClosing);
  self.Shown += new System.EventHandler(@self.Maker_Shown);
  self.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(@self.Maker_MouseDoubleClick);
  self.MouseDown += new System.Windows.Forms.MouseEventHandler(@self.Maker_MouseDown);
  self.MouseMove += new System.Windows.Forms.MouseEventHandler(@self.Maker_MouseMove);
  self.MouseUp += new System.Windows.Forms.MouseEventHandler(@self.Maker_MouseUp);
  self.Paint += new System.Windows.Forms.PaintEventHandler(@self.Maker_Paint);
  self.ObjectPopup.ResumeLayout(false);
  self.ResumeLayout(false);

我做错了什么?请帮助我对此感到沮丧,因为我的程序的其他部分有 mousemove 事件。他们工作得很好。我似乎无法弄清楚为什么这个特定的鼠标移动事件会发生。

Either I am not totally understanding how events work or Delphi Prism has gone mad!!!

I have a winform, mousedown event and mousemove event. Whenever I click the left mouse button only, MouseDown event fires as expected but ALSO MouseMove event fires right after when it is not suppose to.

Here is the piece of code from my winform designer where the methods are assigned to events.

  self.ClientSize := new System.Drawing.Size(751, 502);
  self.KeyPreview := true;
  self.Name := 'Maker';
  self.Text := 'Window Maker';
  self.Load += new System.EventHandler(@self.Maker_Load);
  self.FormClosing += new System.Windows.Forms.FormClosingEventHandler(@self.Maker_FormClosing);
  self.Shown += new System.EventHandler(@self.Maker_Shown);
  self.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(@self.Maker_MouseDoubleClick);
  self.MouseDown += new System.Windows.Forms.MouseEventHandler(@self.Maker_MouseDown);
  self.MouseMove += new System.Windows.Forms.MouseEventHandler(@self.Maker_MouseMove);
  self.MouseUp += new System.Windows.Forms.MouseEventHandler(@self.Maker_MouseUp);
  self.Paint += new System.Windows.Forms.PaintEventHandler(@self.Maker_Paint);
  self.ObjectPopup.ResumeLayout(false);
  self.ResumeLayout(false);

What am I doing wrong? Please, help I am getting frustrated over this, because I have mousemove events in other parts of my program. They work fine. I can't seem to figure out why this perticular mousemove event is acting up.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情域 2024-12-26 22:34:45

我忘记了发生这种情况的原因。

但对于一个可能的解决方法:

Point _LastPoint = Point.Empty;

private void Form1_MouseMove(object sender, MouseEventArgs e) {
  if (_LastPoint != e.Location) {
    _LastPoint = e.Location;
    // run MouseMove code:
  }
}

I forget the reason that happens.

But for a possible work around:

Point _LastPoint = Point.Empty;

private void Form1_MouseMove(object sender, MouseEventArgs e) {
  if (_LastPoint != e.Location) {
    _LastPoint = e.Location;
    // run MouseMove code:
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文