如何以编程方式单击复选框? [英] How to click a checkbox programmatically?

查看:67
本文介绍了如何以编程方式单击复选框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以自己调用chkMyCheckBox_CheckedChanged(),但这是对点击的响应,而不是点击本身。虽然这对于一个

按钮是好的,但它对于一个复选框来说是不够的,因为复选框应该更新它的位置。
更新它的位置。当然,我可以将复选框设置为

新值(需要反转其当前值)。


有更好的方法吗?


(更一般地说,我的问题是:我有一些用于某些设置的GUI,而且我想要程序以编程方式设置其中一些,在启动时。

GUI应该反映所做出的决定。如果用户加载程序,最终结果应为=

,然后转到设置,然后单击

打开和关闭一些选项。)


Zytan

I could call chkMyCheckBox_CheckedChanged() myself, but this is the
response to the click, not the click itself. While this is fine for a
button, it is insufficent for a check box, as the check box should
update its position. Of course, I could just set the check box to the
new value (which required inverting its current value).

Is there a better way?

(More generally, my issue is: I have a GUI for some settings, and I
want the program to set some of them programatically, at start up.
The GUI should reflect the decisions made. The end result should = as
if the user loaded the program, and went to the settings, and clicked
some options on and off.)

Zytan

推荐答案



" Zytan" < zy ********** @ gmail.comwrote in message

news:11 ******************** **@e51g2000hsg.googlegr oups.com ...

"Zytan" <zy**********@gmail.comwrote in message
news:11**********************@e51g2000hsg.googlegr oups.com...

>我可以自己调用chkMyCheckBox_CheckedChanged(),但这是

响应点击,而不是点击本身。虽然这对于一个

按钮是好的,但它对于一个复选框来说是不够的,因为复选框应该更新它的位置。
更新它的位置。当然,我可以将复选框设置为

新值(需要反转其当前值)。


有更好的方法吗?


(更一般地说,我的问题是:我有一些用于某些设置的GUI,而且我想要程序以编程方式设置其中一些,在启动时。

GUI应该反映所做出的决定。如果用户加载程序,最终结果应为=

,然后转到设置,然后单击

打开和关闭一些选项。)
>I could call chkMyCheckBox_CheckedChanged() myself, but this is the
response to the click, not the click itself. While this is fine for a
button, it is insufficent for a check box, as the check box should
update its position. Of course, I could just set the check box to the
new value (which required inverting its current value).

Is there a better way?

(More generally, my issue is: I have a GUI for some settings, and I
want the program to set some of them programatically, at start up.
The GUI should reflect the decisions made. The end result should = as
if the user loaded the program, and went to the settings, and clicked
some options on and off.)



就是这样。


chkMyCheckBox.Value = true; ''true = checked false =未选中。


您最有可能需要全局OnStatup-flag = true,因为设置

chkbox。 Value = true将触发chkbox_Changed事件。检查

更改事件中的Onstart-flag = true允许您在应用启动期间绕过执行代码

。然后在app

启动后设置flag = false。

That would be this.

chkMyCheckBox.Value = true; '' true = checked false = unchecked.

You''ll most likely need a global OnStatup-flag = true as well, as setting
chkbox.Value = true is going to fire the chkbox_Changed event. Checking the
Onstart-flag = true in the Change Event allows you to bypass executing code
in the event during app start-up. Then you set the flag = false after app
start-up.


" Zytan" < zy ********** @ gmail.comwrote in message

news:11 ******************** **@e51g2000hsg.googlegr oups.com ...
"Zytan" <zy**********@gmail.comwrote in message
news:11**********************@e51g2000hsg.googlegr oups.com...

>我可以自己调用chkMyCheckBox_CheckedChanged(),但这是

响应点击,而不是点击本身。虽然这对于一个

按钮是好的,但它对于一个复选框来说是不够的,因为复选框应该更新它的位置。
更新它的位置。当然,我可以将复选框设置为

新值(需要反转其当前值)。
>I could call chkMyCheckBox_CheckedChanged() myself, but this is the
response to the click, not the click itself. While this is fine for a
button, it is insufficent for a check box, as the check box should
update its position. Of course, I could just set the check box to the
new value (which required inverting its current value).



这是一个坏主意。你不应该直接打电话给事件。

This is a bad idea. You should never call an event directly.


" Mr。阿诺德" < MR。 Ar****@Arnold.com 在留言中写道

news:e4 ***** ********* @ TK2MSFTNGP04.phx.gbl ...
"Mr. Arnold" <MR. Ar****@Arnold.comwrote in message
news:e4**************@TK2MSFTNGP04.phx.gbl...

你很可能还需要一个全局的OnStatup-flag = true ,设置

chkbox.Value = true将触发chkbox_Changed事件。检查

更改事件中的Onstart-flag = true允许您在应用启动期间绕过执行

代码。然后在

app启动后设置flag = false。
You''ll most likely need a global OnStatup-flag = true as well, as setting
chkbox.Value = true is going to fire the chkbox_Changed event. Checking
the Onstart-flag = true in the Change Event allows you to bypass executing
code in the event during app start-up. Then you set the flag = false after
app start-up.



OP想要复选框更改事件。


Michael

The OP wants the checkbox change event to fire.

Michael

这篇关于如何以编程方式单击复选框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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