简体   繁体   English

使用 Windows 窗体初始化程序时,如何从工具条中选择要检查的按钮?

[英]How can I select which button from a toolstrip is checked when the program is initialized using Windows Forms?

I have a windows form that used to have 4 buttons(btn1,btn2,btn3,btn4) in a toolstrip, I added a new button (btnNew).我有一个 windows 窗体,它曾经在工具条中有 4 个按钮(btn1、btn2、btn3、btn4),我添加了一个新按钮(btnNew)。 When my application starts I wanted this new button to be pre selected.当我的应用程序启动时,我希望预先选择这个新按钮。

I tried changing in the properties of btnNew to "checked = true" and "checkstate = checked".我尝试将 btnNew 的属性更改为“checked = true”和“checkstate = checked”。 But when I start the application my new button is not selected!但是当我启动应用程序时,我的新按钮没有被选中!

What is weird is that all of the other buttons are "checked=false" and "Checkstate=unchecked".奇怪的是,所有其他按钮都是“checked=false”和“Checkstate=unchecked”。 If I selected one of the old buttons before closing the program, when I start it again the last selected button is still selected.如果我在关闭程序之前选择了一个旧按钮,当我再次启动它时,最后选择的按钮仍然被选中。 Except for the btnNew, independent of the which btn is with the "checked=true" state it is the only that is never pre selected when it re-starts.除了 btnNew,与哪个 btn 处于“checked=true”状态无关,它是唯一一个在重新启动时从未被预选的。

And if change the "checked" and "checkstate" for the other buttons they also are not initialized selected.如果更改其他按钮的“已检查”和“检查状态”,它们也不会被初始化选择。 With the exception for the btn4!除了 btn4! This one is always selected when started but if I select another button before closing, then they both are selected when started (and I really don't want these!!!)这个总是在开始时被选中,但是如果我在关闭之前选择另一个按钮,那么它们在开始时都会被选中(我真的不想要这些!!!)

I would accept if the last select is still selected when it restarts or any button select tbh.如果在重新启动时仍然选择最后一个选择或任何按钮选择 tbh,我会接受。 Do you guys have any idea of what could be causing it or how to solve it?你们有什么想法可能导致它或如何解决它? Seriously, any ideas are welcome!说真的,欢迎任何想法!

I will assume when you say button you are talking about a ToolStripButton , and when you say selected you mean pressed.我假设当你说 button 时你在谈论ToolStripButton ,当你说 selected 时你的意思是按下。 The property CheckOnClick must be set to True for the button to remain pressed.必须将属性CheckOnClick设置为 True 才能使按钮保持按下状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM