首页 \ 问答 \ 我有一个WinForms“按钮”,如何在不激活按钮的情况下单击并拖动它?(I have a WinForms “button”, how do I click and drag it without activating the button?)

我有一个WinForms“按钮”,如何在不激活按钮的情况下单击并拖动它?(I have a WinForms “button”, how do I click and drag it without activating the button?)

我的WinForm只是一个40x40按钮,用户可以点击呼叫寻求帮助。 一切正常,除非您单击并拖动以将按钮移动到屏幕的其他部分,按钮在释放鼠标左键后激活(完成“单击”)。 有没有办法在mousedown事件发生时检查窗口是否已移动并在此情况下停止mouseclick事件?

我目前如何“点击并拖动”:

    private void btn_MouseDown(object sender, MouseEventArgs e)
    {
        if (e.Button == System.Windows.Forms.MouseButtons.Left)
        {
            MouseDownLocation = e.Location;
        }
    }

    private void btn_MouseMove(object sender, MouseEventArgs e)
    {
        if (e.Button == System.Windows.Forms.MouseButtons.Left)
        {
            this.Left = e.X + this.Left - MouseDownLocation.X;
            this.Top = e.Y + this.Top - MouseDownLocation.Y;
        }
    }

My WinForm is just a 40x40 button that users can click to call for help. Everything works except when you click and drag to move the button to a different part of the screen the button activates after releasing the left mouse button (completing the "click"). Is there a way to check if the window has moved while the mousedown event is happening and stop the mouseclick event in that case?

How I am currently doing "click and drag":

    private void btn_MouseDown(object sender, MouseEventArgs e)
    {
        if (e.Button == System.Windows.Forms.MouseButtons.Left)
        {
            MouseDownLocation = e.Location;
        }
    }

    private void btn_MouseMove(object sender, MouseEventArgs e)
    {
        if (e.Button == System.Windows.Forms.MouseButtons.Left)
        {
            this.Left = e.X + this.Left - MouseDownLocation.X;
            this.Top = e.Y + this.Top - MouseDownLocation.Y;
        }
    }

原文:
更新时间:2021-12-10 17:12

最满意答案

所以,我不喜欢它,但这就是我想出的:我编写了一个脚本,将整个环境输出为一行,我在调用的过程之后调用它,作为一部分相同的命令。 之后,我可以分析输出,从最后一行提取环境,并丢弃它,以便处理原始进程的输出。

有很多选项可以实现这一点。 我所做的是:

1)创建一个Python脚本,命名它,例如printenv ,如下所示:

#!/usr/bin/python2.7
import os
print os.environ

2)当调用我的进程时,而不是<some command>我调用<some command> && printenv

当然,脚本不必使用Python,也不必以Python的print格式输出环境。 (但是这种格式非常方便,例如可以传递给JavaScript赋值。)


So, I don't like it, but this is what I've come up with: I've written a script that outputs the whole environment as a single line, and I'm calling it right after my invoked process, as part of the same command. After that I can analyse the output, extracting the environment from the last line, and discarding it in order to process the output from my original process.

There are many options to implement this. What I've done is along the lines of:

1) Creating a Python script, naming it, for example printenv, which looks like this:

#!/usr/bin/python2.7
import os
print os.environ

2) When invoking my process, instead of <some command> I invoke <some command> && printenv.

Of course, the script does not have to be in Python, and it does not have to output the environment in Python's print format. (But this format is rather convenient, and can be passed to a JavaScript assignment, for example.)

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。