我有一个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 themouseclick
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; } }
原文:
最满意答案
所以,我不喜欢它,但这就是我想出的:我编写了一个脚本,将整个环境输出为一行,我在调用的过程之后调用它,作为一部分相同的命令。 之后,我可以分析输出,从最后一行提取环境,并丢弃它,以便处理原始进程的输出。
有很多选项可以实现这一点。 我所做的是:
1)创建一个Python脚本,命名它,例如
printenv
,如下所示:#!/usr/bin/python2.7 import os print os.environ
2)当调用我的进程时,而不是
<some command>
我调用<some command> && printenv
。当然,脚本不必使用Python,也不必以Python的
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
相关问答
更多-
TCP/IP模型是一个________。[2023-05-19]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
等待PHP中执行Javascript函数的结束[重复](Wait for end of execution of a Javascript function in PHP [duplicate])[2022-07-21]
你不能做你想做的事。 代码的php部分是在Web服务器上生成的。 这会生成一堆文本,作为一个整体发送给客户端。 PHP死了。 然后,用户计算机上的浏览器会解释此文本并显示它。 这台计算机不知道服务器php代码希望做什么。 它只能看到一个准备好的文本。 然后它执行javascript代码。 You can't do what you wish to do. The php part of the code is generated on the webserver. This generates a bunc ... -
在fork()之前停止,在exec()之前 这个很容易,但不是那么有用: import subprocess, os, signal proc = subprocess.Popen( ['binary', 'arg1', 'arg2'], preexec_fn=lambda: os.kill(os.getpid(), signal.SIGSTOP), ) 为什么“不那么有用”? 因为preexec_fn在新PID中运行时,您的意图似乎涉及收集内存使用情况的统计信息(在程序执行malloc( ...
-
你必须以某种方式输出变量的内容。 您正在生成一个不会传播环境变量的新进程,因此您的python应用程序将不会看到这些值。 您可以使脚本将其回显到某些文件,或者尽可能使标准输出回显。 (从技术上讲,如果你真的想要破解它,就可以停止进程并提取值,但这是一个坏主意。) You'll have to output the variables' content somehow. You're spawning a new process which will not propagate the environment ...
-
你可以使用cwd: foo = check_output("pwd", cwd="/MYABSPATH", shell=True) You could use cwd: foo = check_output("pwd", cwd="/MYABSPATH", shell=True)
-
不确定这是否是你所追求的,但只有在用户任务2完成后才会调用包含“狗”任务的子进程。 在该示例中,用户任务2是一个用户任务,但它可以很容易地成为服务或脚本任务。 这样,无论用户任务1是否完成,子过程2(包含狗)都会在先决条件完成后立即运行。 如果我错过了您的具体要求,请告诉我。 格雷格 Not sure if this is what you are after, but the subprocess containing "the Dogs" task will only be called after U ...
-
如何隐藏子进程的输出并继续脚本执行?(How do I hide the output from a subprocess and continue the script execution?)[2022-11-04]
在示例代码中调用subprocess.Popen()之后,主进程将立即进入print()语句,然后执行doMoreStuff(),同时运行其余的脚本。 After calling subprocess.Popen() in your sample code, the main process will immediately comes to the print() statement and then execute doMoreStuff(), running the rest of script si ... -
将环境传递给父级的python shell脚本执行(python shell script execution that passes environment to the parent)[2022-03-01]
恕我直言,最简单的解决方案是创建一个新的shell脚本(让我们称之为run_black_box.sh ),它将安装脚本(让我们假设它命名为setup.sh )来源初始化环境,然后调用black_box程序。 以下是run_black_box.sh的可能内容: #/bin/bash source setup.sh black_box 您可以将run_black_box.sh传递给subprocess run_black_box.sh以执行。 IMHO the simplest solution consis ... -
所以,我不喜欢它,但这就是我想出的:我编写了一个脚本,将整个环境输出为一行,我在调用的过程之后调用它,作为一部分相同的命令。 之后,我可以分析输出,从最后一行提取环境,并丢弃它,以便处理原始进程的输出。 有很多选项可以实现这一点。 我所做的是: 1)创建一个Python脚本,命名它,例如printenv ,如下所示: #!/usr/bin/python2.7 import os print os.environ 2)当调用我的进程时,而不是
我调用 & ...