需要实现:工具栏中A按钮点击后按钮A需下陷,点击工具栏上B按钮后B按钮需下陷,A显示正常,请问如何实现?

解决方案 »

  1.   

    问题2:像vs.net2005开发工具中 工具-->选项中  左侧是操作目录树形菜单,右侧显示各操作内容,点其中一个菜单,右侧是切换form吗?要如果实现这种效果?
      

  2.   

    click事件?click事件不能使它下陷。
      

  3.   

    如果你主要想实现一个类似的互拆效果,在两个按钮的CheckedChanged事件中判断该按钮是否选中,如果是就将另一个Checked置为false就可以了。
    如果你主要是想要“下陷”的那种视觉效果,你可能写点重绘代码(根据其是否选中)!
    对了,至于Click事件不能使它下陷,是不是没有设置CheckedOnClick?
      

  4.   

    你要是会Visible = false;你就明白了
      

  5.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Windows.Forms.VisualStyles;namespace WindowsApplication153
    {
        public partial class Form1 : Form
        {
            List<ToolStripButtonEx> Group = new List<ToolStripButtonEx>();        public Form1()
            {
                InitializeComponent();            ToolStrip TS = new ToolStrip();
                TS.Parent = this;
                TS.RenderMode = ToolStripRenderMode.System;            ToolStripButtonEx A = new ToolStripButtonEx();
                A.DisplayStyle = ToolStripItemDisplayStyle.Text;
                A.Text = "AAA";
                A.Click += new EventHandler(ToolStripButtonEx_Click);
                TS.Items.Add(A);
                Group.Add(A);            ToolStripButtonEx B = new ToolStripButtonEx();
                B.DisplayStyle = ToolStripItemDisplayStyle.Text;
                B.Text = "BBB";
                B.Click += new EventHandler(ToolStripButtonEx_Click);
                TS.Items.Add(B);
                Group.Add(B);
            }        void ToolStripButtonEx_Click(object sender, EventArgs e)
            {
                ToolStripButtonEx CurrentTSBEx = (ToolStripButtonEx)sender;            foreach (ToolStripButtonEx TSBEx in Group)
                    if (TSBEx != CurrentTSBEx)
                        TSBEx.IsPressed = false;            CurrentTSBEx.IsPressed = !CurrentTSBEx.IsPressed;
            }        class ToolStripButtonEx : ToolStripButton
            {
                bool _IsPressed = false;            public override bool Pressed
                {
                    get
                    {
                        return IsPressed;
                    }
                }            public bool IsPressed
                {
                    get
                    {
                        return _IsPressed;
                    }                set
                    {
                        _IsPressed = value;
                        this.Invalidate();
                    }
                }
            }
        }
    }