工具条与复选按钮组 [英] Toolstrip with check button group

查看:142
本文介绍了工具条与复选按钮组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有一些按钮的工具条就可以了(WinFroms / C#/。NET4)。我想有点击的按钮进行检查和所有其他未检查的,所以我想有只点击的按钮选中,所有其他未选中状态。

I'd like to have a toolstrip with some buttons on it (WinFroms/c#/.net4). I'd like to have the clicked button be checked and all others unchecked, so I want to have only the clicked button checked, all the others unchecked.

我知道工具条按钮checkedonlclick属性,但是当我点击一个按钮,其他人也可以进行检查。在良好的旧VB6有针对此问题的自动解决方案:ButtonGroup的工具栏上。是否有Winfoms任何类似的?

I know toolstrip button has checkedonlclick property, but when I click one button, others may be also checked. In good old VB6 there was an automatic solution for this problem: buttongroup on toolbar. Is there any similar in Winfoms?

或者我应该从code处理呢?交换机的所有其他按钮选中状态时被选中一个按钮?如果是的话,那就不是我最喜欢的解决方案...

Or should I handle it from code?! Switch all other buttons to unchecked state when one button is checked? If so, then it would not be my favourite solution...

推荐答案

称这个code在toolStripButton_Click活动,你应该得到期望的结果。

Call this code on the toolStripButton_Click events and you should get the desired result.

   foreach (ToolStripButton item in ((ToolStripButton)sender).GetCurrentParent().Items)
   {
       if (item == sender) item.Checked = true;
       if ((item != null) && (item != sender))
       {
          item.Checked = false;
       }
   }

这篇关于工具条与复选按钮组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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