Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Enabling hotkeys for mmTabControl
Message
From
06/07/2006 18:12:21
 
 
To
All
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Title:
Enabling hotkeys for mmTabControl
Miscellaneous
Thread ID:
01134307
Message ID:
01134307
Views:
59
Hi Kevin,

Please consider adding this change to mmTabControl.cs.
This will allow "&"-marked HotKeys to work on tab labels.
private void InitializeComponent()
{
   // 
   // mmTabControl
   // 
   this.SelectedIndexChanged += new     
      System.EventHandler(this.mmTabControl_SelectedIndexChanged);
            
   // ***NEW*** allow control elements to be drawn manually
   this.DrawMode = TabDrawMode.OwnerDrawFixed;
}
And this code:
        /// <summary>
        /// Processes hotkey, if any
        /// </summary>
        /// <param name="charCode">hotkey pressed</param>
        /// <returns>true</returns>
        protected override bool ProcessMnemonic(char charCode)
        {
            for (int i = 0; i < this.TabPages.Count; i++)
            {
                if (Control.IsMnemonic(charCode, TabPages[i].Text))
                {
                    this.SelectedTab = TabPages[i];
                    this.Focus();
                    break;
                }
            }
            return true;
        }

        /// <summary>
        /// Raises the System.Windows.Forms.TabControl.DrawItem event
        /// </summary>
        /// <param name="e">DrawItemEventArgs</param>
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            base.OnDrawItem(e);
            Graphics graphics = e.Graphics;

            StringFormat stringFormat = new StringFormat();
            stringFormat.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show;
            stringFormat.LineAlignment = StringAlignment.Center;
            stringFormat.Alignment = StringAlignment.Center;

            graphics.DrawString(
                this.TabPages[e.Index].Text,
                this.Font,
                SystemBrushes.WindowText,
                this.GetTabRect(e.Index),
                stringFormat);
        }
Thanks!
Next
Reply
Map
View

Click here to load this message in the networking platform