简体   繁体   English

Winform ToolStrip中的选择按钮

[英]Selecting button in Winform ToolStrip

在此处输入图片说明

Reference Image 参考图片

I want to select a button("Exit") on the ToolStrip after pressing a button ("ButtonFocus To Exit") outside the toolstrip. 我要在工具栏上按下按钮(“要退出的按钮焦点”)后在工具栏上选择按钮(“退出”)。

I used ExitToolStripButton.Select() on ButtonFocusToExit.Click but which seems like its selecting the button ("Exit") but when i pressed enter it never execute the code in "ExitToolStripButton_Click" . 我在ButtonFocusToExit.Click上使用ExitToolStripButton.Select() ,但似乎选择了按钮(“ Exit”),但是当我按Enter时,它永远不会执行“ ExitToolStripButton_Click”中的代码。

So the button is still not active. 因此,该按钮仍未激活。 Can anyone have fix to it? 谁能解决这个问题?

Got the solution ... 得到了解决方案...

First focus on the ToolStrip and then Select the Control on the Toolstrip 首先将重点放在工具栏上,然后在工具栏上选择控件

ToolStrip1.Focus() ToolStrip1.Focus()

ExitToolStripButton.Select() ExitToolStripButton.Select()

Check if event is missing the event handler 检查事件是否缺少事件处理程序

Select the ExitToolStripButton > go to properties > events tab> Click Event > select the ExitToolStripButton_Click 选择ExitToolStripButton>转到属性>事件选项卡>单击事件>选择ExitToolStripButton_Click

You want to execute the ExitToolStripButton codebehind? 您要在后面执行ExitToolStripButton代码吗? You can call ExitToolStripButton.PerformClick() ; 您可以调用ExitToolStripButton.PerformClick() ;

Make sure it has focus. 确保它具有焦点。 Are you sure the function you are using actually give the object focus? 您确定所使用的功能实际上使对象聚焦吗? It could just give it the appearance of selection. 它可能只是使其具有选择的外观。

According to MSDN: 根据MSDN:

Select  |  Selects the item. (inherited from ToolStripItem)

It doesn't say anything about focusing it. 它没有说出任何关于它的关注。

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

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