0
Answer

ToolStripSplitButton

j_sen21

j_sen21

14y
6.9k
1

Hello,
This is a loaded question. I need to show a checked property on the ToolStripSplitButton itself when clicked. In Visual Studio 2005 it shows a orange background when buttons.checked = true. It seems they changed that in VS 2008 to a blue border? Anyways, I found this code to override the onPaint, but I still don't know how to make the icons appear with a orange background like in VS 2005.  Here is the code I found.
Thanks in advance..
//Control
using System;
using System.Collections.Generic;
using System.Text;
 
namespace WindowsForm_Examples_NET_2
{
    class CheckToolstripSplitButton : System.Windows.Forms.ToolStripSplitButton
    {
        private bool _isChecked;
 
        public bool IsChecked
        {
            get { return _isChecked; }
            set { _isChecked = value;
            Invalidate();
            }
        }
        public CheckToolstripSplitButton()
        {
            this.Padding = new System.Windows.Forms.Padding(50, 0, 0, 0);
        }
        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            base.OnPaint(e);
            if (IsChecked)
            {
                e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                e.Graphics.FillEllipse(new System.Drawing.SolidBrush(System.Drawing.Color.Black), new System.Drawing.Rectangle(5, 5, 10, 10));
            }
        }
    }
}
 
 
//Implementation
        private void Form2_Load(object sender, EventArgs e)
        {
            CheckToolstripSplitButton button1 = new CheckToolstripSplitButton();
            button1.DisplayStyle = ToolStripItemDisplayStyle.Text;
            button1.Text = "Your Button Text";
            button1.IsChecked = true;
            toolStrip1.Items.Add(button1);
        }