需要一种方法来判断System.Windows.Forms.Button是否被“压低”。 (推下去) [英] Need a way to tell if a System.Windows.Forms.Button is "depressed" (pushed down)

查看:94
本文介绍了需要一种方法来判断System.Windows.Forms.Button是否被“压低”。 (推下去)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我正试图找出一种方法来判断.NET窗体是否形成按钮

(System.Windows.Forms.Button)是郁闷 ; (推下去)。对于我的

应用程序,我不能使用复选框控件设置为按钮样式,我必须使用System.Windows.Forms.Button
。当我被迫按下时,我找不到告诉

的方法。


我尝试用按钮手柄调用API SendMessage并且

BM_GETSTATE获取按钮的状态。这只会在按钮具有焦点(BST_FOCUS)时返回

。即使按下按钮,它也永远不会返回结果

BST_PUSHED。

任何想法?

杰夫

Hello,
I am trying to find a way to tell if an .NET windows forms Button
(System.Windows.Forms.Button) is "depressed" (pushed down). For my
application, I can not use a check box control set to button style, I
must use a System.Windows.Forms.Button. I can not find a way to tell
when it is momentaraly pressed.

I tried calling the API SendMessage with the button handle and
BM_GETSTATE to get the state of the button. This will only return when
the button has focus (BST_FOCUS). It will never return a result with
BST_PUSHED even when the button is in fact pressed down.
Any ideas?
Jeff

推荐答案

Jeff,

您是否考虑过使用带有

的CheckBox或RadioButton控件外观属性设置为Button?


这会导致CheckBox或RadioButton看起来像普通Button,但

继续作为CheckBox运行(切换)或RadioButton。


你可以设置CheckBox或RadioButton的AutoCheck属性,如果你是
不想让它们停下来。


希望这有帮助

Jay


< jr ******* @ hotmail.com>在消息中写道

news:11 ********************** @ f14g2000cwb.googlegr oups.com ...
Jeff,
Have you considered using a CheckBox or RadioButton control with the
Appearance property set to Button?

This causes the CheckBox or RadioButton to look like a normal Button, but
continue to function (toggle) as a CheckBox or RadioButton.

You can set the AutoCheck property of the CheckBox or RadioButton if you
don''t want them to stay down.

Hope this helps
Jay

<jr*******@hotmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
你好,
我试图找到一种方法来判断一个.NET窗体是否形成按钮
(System.Windows.Forms.Button)是郁闷的。 (推下去)。对于我的
应用程序,我不能使用复选框控件设置为按钮样式,我必须使用System.Windows.Forms.Button。我找不到告诉
什么时候按下它的方法。

我尝试用按钮手柄调用API SendMessage并使用BM_GETSTATE来获取按钮的状态。这只会在按钮具有焦点(BST_FOCUS)时返回。即使按下按钮,它也永远不会返回结果BST_PUSHED。
任何想法?
Jeff
Hello,
I am trying to find a way to tell if an .NET windows forms Button
(System.Windows.Forms.Button) is "depressed" (pushed down). For my
application, I can not use a check box control set to button style, I
must use a System.Windows.Forms.Button. I can not find a way to tell
when it is momentaraly pressed.

I tried calling the API SendMessage with the button handle and
BM_GETSTATE to get the state of the button. This will only return when
the button has focus (BST_FOCUS). It will never return a result with
BST_PUSHED even when the button is in fact pressed down.
Any ideas?
Jeff



Jay,

感谢您的建议。我尝试使用CheckBox和

RadioButton。它们都不起作用,因为在用户释放鼠标左键之前,它们的Checked属性不是设置为
。如果你创建一个

按钮,用鼠标左键单击它并按住鼠标按钮

向下你会看到按钮保持向下推。 CheckChanged

事件未被触发,OnClick事件未被触发,Checked属性为

False,直到您释放鼠标按钮。我希望能够在按钮实际按下时按下
告诉按下(按下)


我在我的按钮上做我自己的画,想要它推下当按下按钮时,通过偏移它来按下

按钮。目前

按钮被推下来,但我画的却没有。


Jeff

Jay B. Harlow [MVP - Outlook]写道:
Jay,
Thanks for the suggestion. I tried using both the CheckBox and
RadioButton. Neither of them work because their Checked property is not
set until the user releases the left mouse button. If you create a
button, click it with the left mouse button and hold the mouse button
down you will see that the button stays "pushed down". The CheckChanged
event is not fired, OnClick event is not fired, and Checked property is
False until you release the mouse button. I am looking to be able to
tell when the button is actually depressed (pushed down)

I am doing my own painting on my button and want it to "push down" with
the button by offsetting it when the button is depressed. Currently the
button gets pushed down but what I painted on it does not.

Jeff
Jay B. Harlow [MVP - Outlook] wrote:
Jeff,
您是否考虑过使用CheckBox或RadioButton控件并将
Appearance属性设置为Button?

这会导致CheckBox或RadioButton看起来像一个普通的按钮,
但继续作为CheckBox或RadioButton运行(切换)。

你可以设置CheckBox或RadioButton的AutoCheck属性,如果
你不希望他们留下来。

希望这有帮助
Jay

< jr ******* @ hotmail。 COM>在消息中写道
新闻:11 ********************** @ f14g2000cwb.googlegr oups.com ...
Jeff,
Have you considered using a CheckBox or RadioButton control with the
Appearance property set to Button?

This causes the CheckBox or RadioButton to look like a normal Button, but continue to function (toggle) as a CheckBox or RadioButton.

You can set the AutoCheck property of the CheckBox or RadioButton if you don''t want them to stay down.

Hope this helps
Jay

<jr*******@hotmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
你好,
我试图找到一种方法来判断一个.NET窗体是否形成按钮
(System.Windows.Forms.Button)是否被压抑。 (推下去)。对于我的
应用程序,我不能使用复选框控件设置为按钮样式,
我必须使用System.Windows.Forms.Button。当我被迫按下时,我无法找到
告诉的方法。

我尝试使用按钮手柄调用API SendMessage并使用BM_GETSTATE来获取按钮的状态。当按钮具有焦点(BST_FOCUS)时,这将仅返回
。即使按下按钮,它也永远不会返回带有BST_PUSHED的结果

任何想法?
Jeff
Hello,
I am trying to find a way to tell if an .NET windows forms Button
(System.Windows.Forms.Button) is "depressed" (pushed down). For my
application, I can not use a check box control set to button style, I must use a System.Windows.Forms.Button. I can not find a way to tell when it is momentaraly pressed.

I tried calling the API SendMessage with the button handle and
BM_GETSTATE to get the state of the button. This will only return when the button has focus (BST_FOCUS). It will never return a result with BST_PUSHED even when the button is in fact pressed down.
Any ideas?
Jeff






这是一个简单的方法。使用按钮的mousedown和mouseup事件。

使用默认值创建一个带有按钮和标签的表单。然后

添加以下代码以查看会发生什么。您仍然可以使用当前使用的绘画

代码,但现在可以使用该按钮作为开/关按钮。

Private Sub Button1_MouseDown(ByVal sender As Object,ByVal e As

System.Windows.Forms.MouseEventArgs)处理Button1.MouseDown

Me.Label1.Text =" Pressed"

End Sub


Private Sub Button1_MouseUp(ByVal sender As Object,ByVal e As

System.Windows.Forms.MouseEventArgs)处理Button1.MouseUp

Me.Label1.Text =" Not Pressed"

End Sub


Lloyd Sheen


< ; JR ******* @ hotmail.com>在消息中写道

news:11 ********************** @ f14g2000cwb.googlegr oups.com ...
Here is a simple way. Use the mousedown and mouseup events of the button.
Create a form with a button and a label using their default values. Then
add the following code to see what happens. You can still use the painting
code you currently use but you can now use the button as an off/on button.
Private Sub Button1_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown
Me.Label1.Text = "Pressed"
End Sub

Private Sub Button1_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles Button1.MouseUp
Me.Label1.Text = "Not Pressed"
End Sub

Lloyd Sheen

<jr*******@hotmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
周杰伦,
感谢您的建议。我尝试使用CheckBox和
RadioButton。它们都不起作用,因为在用户释放鼠标左键之前,它们的Checked属性没有设置。如果你创建了一个
按钮,用鼠标左键单击它并按住鼠标按钮
,你会看到按钮保持向下推。在您释放鼠标按钮之前,不会触发CheckChanged
事件,不触发OnClick事件,并且Checked属性为
False。我希望能够告诉按钮何时被按下(按下)

我在我的按钮上做自己的画,并希望它按下按钮。按下按钮,按下按钮,按下按钮。目前
按钮被推下来,但我画的却没有。

杰夫

Jay B. Harlow [MVP - Outlook]写道:
Jay,
Thanks for the suggestion. I tried using both the CheckBox and
RadioButton. Neither of them work because their Checked property is not
set until the user releases the left mouse button. If you create a
button, click it with the left mouse button and hold the mouse button
down you will see that the button stays "pushed down". The CheckChanged
event is not fired, OnClick event is not fired, and Checked property is
False until you release the mouse button. I am looking to be able to
tell when the button is actually depressed (pushed down)

I am doing my own painting on my button and want it to "push down" with
the button by offsetting it when the button is depressed. Currently the
button gets pushed down but what I painted on it does not.

Jeff
Jay B. Harlow [MVP - Outlook] wrote:
Jeff,
您是否考虑过使用CheckBox或RadioButton控件并将
Appearance属性设置为Button?

这会导致CheckBox或RadioButton看起来像一个普通按钮,
Jeff,
Have you considered using a CheckBox or RadioButton control with the
Appearance property set to Button?

This causes the CheckBox or RadioButton to look like a normal Button,


继续作为CheckBox或RadioButton运行(切换)。

您可以设置CheckBox的AutoCheck属性或RadioButton if
continue to function (toggle) as a CheckBox or RadioButton.

You can set the AutoCheck property of the CheckBox or RadioButton if


不希望他们留下来。

希望这有帮助
Jay

< jr ******* @ hotmail.com>在消息中写道
新闻:11 ********************** @ f14g2000cwb.googlegr oups.com ...
don''t want them to stay down.

Hope this helps
Jay

<jr*******@hotmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
>你好,
>我试图找到一种方法来判断.NET窗口是否形成按钮
> (System.Windows.Forms.Button)被压低。 (推下去)。对于我的
>应用程序,我不能使用复选框控件设置按钮样式,我>必须使用System.Windows.Forms.Button。我无法找到告诉>的方法当它被瞬间按下时。
>
>我尝试使用按钮手柄调用API SendMessage并且
> BM_GETSTATE获取按钮的状态。这只会在>时返回按钮具有焦点(BST_FOCUS)。它将永远不会返回>即使按下按钮,BST_PUSHED也是如此。
>有什么想法吗?
>杰夫
>
> Hello,
> I am trying to find a way to tell if an .NET windows forms Button
> (System.Windows.Forms.Button) is "depressed" (pushed down). For my
> application, I can not use a check box control set to button style, I > must use a System.Windows.Forms.Button. I can not find a way to tell > when it is momentaraly pressed.
>
> I tried calling the API SendMessage with the button handle and
> BM_GETSTATE to get the state of the button. This will only return when > the button has focus (BST_FOCUS). It will never return a result with > BST_PUSHED even when the button is in fact pressed down.
> Any ideas?
> Jeff
>



这篇关于需要一种方法来判断System.Windows.Forms.Button是否被“压低”。 (推下去)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆