Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. OwnerDrawn TabControl behaving differently in Design Mode [modified] [solved]

OwnerDrawn TabControl behaving differently in Design Mode [modified] [solved]

Scheduled Pinned Locked Moved C#
graphicsdesignquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TheFoZ
    wrote on last edited by
    #1

    Hi All. I have been developing my own OwnerDrawn TabControl so I can have a close button on the right hand side of the tab. All was going well thanks to some of the articles on CP and now it has stopped working in Design mode. When the control is used in the test form when the app is running, everything works as expected. In design mode I cannot switch tabs to add controls to them. Any ideas?

    public class ClosableTabCtrl : TabControl
    {
    #region Private Members
        private System.Windows.Forms.ImageList buttonImageList;
    
        private bool showCloseButton = true;
        private bool hideCloseButtonWhenOnlyOneTab;
    
        private const string tabText = "      ";
    
        private int buttonImageIndex;
    #endregion
    
        public ClosableTabCtrl() : base()
        {
            buttonImageList = new ImageList();
    
            buttonImageList.Images.Add((Image)new Bitmap(Resources.InactiveCross));
            buttonImageList.Images.Add((Image)new Bitmap(Resources.ActiveCross));
            buttonImageList.Images.Add((Image)new Bitmap(Resources.ClickedCross));
    
            this.DrawMode = TabDrawMode.OwnerDrawFixed;
            this.DrawItem += new DrawItemEventHandler(ClosableTabCtrl\_DrawItem);
    
            this.MouseMove += new MouseEventHandler(ClosableTabCtrl\_MouseMove);
            this.MouseLeave += new EventHandler(ClosableTabCtrl\_MouseLeave);
            this.MouseClick += new MouseEventHandler(ClosableTabCtrl\_MouseClick);
            this.MouseDown += new MouseEventHandler(ClosableTabCtrl\_MouseDown);
            this.MouseUp += new MouseEventHandler(ClosableTabCtrl\_MouseUp);
    
            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
        }
    
        void ClosableTabCtrl\_MouseUp(object sender, MouseEventArgs e)
        {
            if (MouseIsOverButton(e) && buttonImageIndex != 1)
            {
                buttonImageIndex = 1;
                this.Invalidate();
            }
        }
    
        void ClosableTabCtrl\_MouseDown(object sender, MouseEventArgs e)
        {
            if (MouseIsOverButton(e) && buttonImageIndex != 2)
            {
                buttonImageIndex = 2;
                this.Invalidate();
            }
        }
    
        void ClosableTabCtrl\_MouseClick(object sender, MouseEventArgs e)
        {
            if (MouseIsOverButton(e))
            {
                // TODO: raise the event
            }
    
    J T 2 Replies Last reply
    0
    • T TheFoZ

      Hi All. I have been developing my own OwnerDrawn TabControl so I can have a close button on the right hand side of the tab. All was going well thanks to some of the articles on CP and now it has stopped working in Design mode. When the control is used in the test form when the app is running, everything works as expected. In design mode I cannot switch tabs to add controls to them. Any ideas?

      public class ClosableTabCtrl : TabControl
      {
      #region Private Members
          private System.Windows.Forms.ImageList buttonImageList;
      
          private bool showCloseButton = true;
          private bool hideCloseButtonWhenOnlyOneTab;
      
          private const string tabText = "      ";
      
          private int buttonImageIndex;
      #endregion
      
          public ClosableTabCtrl() : base()
          {
              buttonImageList = new ImageList();
      
              buttonImageList.Images.Add((Image)new Bitmap(Resources.InactiveCross));
              buttonImageList.Images.Add((Image)new Bitmap(Resources.ActiveCross));
              buttonImageList.Images.Add((Image)new Bitmap(Resources.ClickedCross));
      
              this.DrawMode = TabDrawMode.OwnerDrawFixed;
              this.DrawItem += new DrawItemEventHandler(ClosableTabCtrl\_DrawItem);
      
              this.MouseMove += new MouseEventHandler(ClosableTabCtrl\_MouseMove);
              this.MouseLeave += new EventHandler(ClosableTabCtrl\_MouseLeave);
              this.MouseClick += new MouseEventHandler(ClosableTabCtrl\_MouseClick);
              this.MouseDown += new MouseEventHandler(ClosableTabCtrl\_MouseDown);
              this.MouseUp += new MouseEventHandler(ClosableTabCtrl\_MouseUp);
      
              SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
              SetStyle(ControlStyles.AllPaintingInWmPaint, true);
          }
      
          void ClosableTabCtrl\_MouseUp(object sender, MouseEventArgs e)
          {
              if (MouseIsOverButton(e) && buttonImageIndex != 1)
              {
                  buttonImageIndex = 1;
                  this.Invalidate();
              }
          }
      
          void ClosableTabCtrl\_MouseDown(object sender, MouseEventArgs e)
          {
              if (MouseIsOverButton(e) && buttonImageIndex != 2)
              {
                  buttonImageIndex = 2;
                  this.Invalidate();
              }
          }
      
          void ClosableTabCtrl\_MouseClick(object sender, MouseEventArgs e)
          {
              if (MouseIsOverButton(e))
              {
                  // TODO: raise the event
              }
      
      J Offline
      J Offline
      Johnny J
      wrote on last edited by
      #2

      I did something similar some time ago (although I don't think I actually inherited from tabControl), and implementing the design time functionality was a little problematic. You can try to have a look at the souce to my Scroll Selector here: ScrollSelector[^] That might give you some pointers... Good luck

      T 1 Reply Last reply
      0
      • J Johnny J

        I did something similar some time ago (although I don't think I actually inherited from tabControl), and implementing the design time functionality was a little problematic. You can try to have a look at the souce to my Scroll Selector here: ScrollSelector[^] That might give you some pointers... Good luck

        T Offline
        T Offline
        TheFoZ
        wrote on last edited by
        #3

        Thanks Johnny J I've had a look through and to be honest I'm not sure how it all works together. I'm having trouble getting it to work in 2008. I'm going to try and build it again from scratch by pasting in the code bit by bit and testing along the way. I was able to select the different tabs in design mode before lunch. I wonder what has happened. If I find out I will post it here. Cheers

        The FoZ

        1 Reply Last reply
        0
        • T TheFoZ

          Hi All. I have been developing my own OwnerDrawn TabControl so I can have a close button on the right hand side of the tab. All was going well thanks to some of the articles on CP and now it has stopped working in Design mode. When the control is used in the test form when the app is running, everything works as expected. In design mode I cannot switch tabs to add controls to them. Any ideas?

          public class ClosableTabCtrl : TabControl
          {
          #region Private Members
              private System.Windows.Forms.ImageList buttonImageList;
          
              private bool showCloseButton = true;
              private bool hideCloseButtonWhenOnlyOneTab;
          
              private const string tabText = "      ";
          
              private int buttonImageIndex;
          #endregion
          
              public ClosableTabCtrl() : base()
              {
                  buttonImageList = new ImageList();
          
                  buttonImageList.Images.Add((Image)new Bitmap(Resources.InactiveCross));
                  buttonImageList.Images.Add((Image)new Bitmap(Resources.ActiveCross));
                  buttonImageList.Images.Add((Image)new Bitmap(Resources.ClickedCross));
          
                  this.DrawMode = TabDrawMode.OwnerDrawFixed;
                  this.DrawItem += new DrawItemEventHandler(ClosableTabCtrl\_DrawItem);
          
                  this.MouseMove += new MouseEventHandler(ClosableTabCtrl\_MouseMove);
                  this.MouseLeave += new EventHandler(ClosableTabCtrl\_MouseLeave);
                  this.MouseClick += new MouseEventHandler(ClosableTabCtrl\_MouseClick);
                  this.MouseDown += new MouseEventHandler(ClosableTabCtrl\_MouseDown);
                  this.MouseUp += new MouseEventHandler(ClosableTabCtrl\_MouseUp);
          
                  SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
                  SetStyle(ControlStyles.AllPaintingInWmPaint, true);
              }
          
              void ClosableTabCtrl\_MouseUp(object sender, MouseEventArgs e)
              {
                  if (MouseIsOverButton(e) && buttonImageIndex != 1)
                  {
                      buttonImageIndex = 1;
                      this.Invalidate();
                  }
              }
          
              void ClosableTabCtrl\_MouseDown(object sender, MouseEventArgs e)
              {
                  if (MouseIsOverButton(e) && buttonImageIndex != 2)
                  {
                      buttonImageIndex = 2;
                      this.Invalidate();
                  }
              }
          
              void ClosableTabCtrl\_MouseClick(object sender, MouseEventArgs e)
              {
                  if (MouseIsOverButton(e))
                  {
                      // TODO: raise the event
                  }
          
          T Offline
          T Offline
          TheFoZ
          wrote on last edited by
          #4

          I rebuilt it from scratch and here is what I found. In the DrawItem method, the design mode does not like it when I change the text of the tab. The line I found to cause the trouble is

          this.TabPages[e.Index].Text = this.TabPages[e.Index].Text.Replace(tabText, string.Empty);

          Looks like I am going to have to actively calculate the size of the tab which is probably the best way to go about it. If anyone can shed some light on the reason for this so I know why I shouldn't do it my original way, I would be grateful. Cheers

          The FoZ

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups