Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 998923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:16:31+00:00 2026-05-16T07:16:31+00:00

I have a class that extends TabControl, basically to have one with the tabs

  • 0

I have a class that extends TabControl, basically to have one with the tabs down the left hand side instead of along the top. To do I have set it to be custom drawn.

The problem is when this is put onto a form via the designer, it easily makes the designer loose track of itself and just give up and display nothing. To fix it I have to close the designer and re-open it and then everything is fine until I hit debug, or I go to a code window for a while and come back, where it gives up again.

Is there anything I can do to help visual studio a bit? As while its not throwing errors, it is getting a little tedious now. I’m using visual studio 2008.

Here is the code that extends the tab control, if anyone sees any issues that could be causing this it’d be very appreciated.

public class VerticalTabControl : TabControl
{
    private Color tabColour1 = Color.AliceBlue;

    public Color TabColour1
    {
        get { return tabColour1; }
        set { tabColour1 = value; this.Refresh(); }
    }

    private Color tabColour2 = Color.White;

    public Color TabColour2
    {
        get { return tabColour2; }
        set { tabColour2 = value; this.Refresh(); }
    }

    private Color selectedTabColor1 = Color.AliceBlue;

    public Color SelectedTabColor1
    {
        get { return selectedTabColor1; }
        set { selectedTabColor1 = value; this.Refresh(); }
    }

    private Color selectedTabColor2 = Color.White;

    public Color SelectedTabColor2
    {
        get { return selectedTabColor2; }
        set { selectedTabColor2 = value; this.Refresh(); }
    }

    private Color backgroundColour = Color.White;

    public Color BackgroundColour
    {
        get { return backgroundColour; }
        set { backgroundColour = value; this.Refresh(); }
    }

    private Color tabTextColour = Color.Black;

    public Color TabTextColour
    {
        get { return tabTextColour; }
        set { tabTextColour = value; this.Refresh(); }
    }

    protected override void OnParentChanged(EventArgs e)
    {
        base.OnParentChanged(e);
        this.Parent.Resize += new EventHandler(Parent_Resize);
    }

    void Parent_Resize(object sender, EventArgs e)
    {
        this.Refresh();
    }


    public VerticalTabControl()
        : base()
    {
        this.Alignment = TabAlignment.Left;
        this.SizeMode = TabSizeMode.Fixed;
        this.ItemSize = new Size(50, 120);
        this.DrawMode = TabDrawMode.OwnerDrawFixed;
        this.DrawItem += new DrawItemEventHandler(VerticalTabControl_DrawItem);          
    }

    void VerticalTabControl_DrawItem(object sender, DrawItemEventArgs e)
    {
        Graphics g = e.Graphics;
        TabControl ctrl = sender as TabControl;
        String sText = ctrl.TabPages[e.Index].Text;

        Rectangle r = new Rectangle(e.Bounds.Left, e.Bounds.Top, e.Bounds.Width, e.Bounds.Height);

        if (e.Index == ctrl.SelectedIndex)
        {
            using (LinearGradientBrush gb = new LinearGradientBrush(r, this.selectedTabColor1, this.selectedTabColor2, LinearGradientMode.Horizontal))
            {
                e.Graphics.FillRectangle(gb, r);
            }
        }
        else
        {
            using (LinearGradientBrush gb = new LinearGradientBrush(r, this.tabColour1, this.tabColour2, LinearGradientMode.Horizontal))
            {
                e.Graphics.FillRectangle(gb, r);
            }
        }

        // Set up the page and the various pieces.
        TabPage page = ctrl.TabPages[e.Index];

        // Set up the offset for an icon, the bounding rectangle and image size and then fill the background.
        int iconOffset = 0;
        Rectangle tabBackgroundRect = e.Bounds;

        // If we have images, process them.
        if (this.ImageList != null)
        {
            // Get sice and image.
            Size size = this.ImageList.ImageSize;
            Image icon = null;
            if (page.ImageIndex > -1)
              icon = this.ImageList.Images[page.ImageIndex];
            else if (page.ImageKey != "")
              icon = this.ImageList.Images[page.ImageKey];

            // If there is an image, use it.
            if (icon != null)
            {
             Point startPoint = new Point(tabBackgroundRect.X + 6,
                   tabBackgroundRect.Y + 2 + ((tabBackgroundRect.Height - size.Height) / 2));
               e.Graphics.DrawImage(icon, new Rectangle(startPoint, size));
                iconOffset = size.Width + 4;
            }
        }

        // Draw out the label.
        SizeF sizeText = g.MeasureString(sText, ctrl.Font);
        int iX = e.Bounds.Left + 6 + iconOffset;
        int iY = e.Bounds.Top + (e.Bounds.Height / 2) - (int)(sizeText.Height / 2);

        using (Brush ForeBrush = new SolidBrush(tabTextColour))
        {
            g.DrawString(sText, ctrl.Font, ForeBrush, iX, iY);
        }

        Rectangle rec = ctrl.GetTabRect(ctrl.TabPages.Count - 1);
        Rectangle recF = new Rectangle(0, rec.Bottom, this.ItemSize.Height, ctrl.Height - rec.Bottom);
        using (SolidBrush bb = new SolidBrush(backgroundColour))
        {
            g.FillRectangle(bb, recF);
        }
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T07:16:31+00:00Added an answer on May 16, 2026 at 7:16 am

    turns out this was the offending bit of code

    protected override void OnParentChanged(EventArgs e)
    {
        base.OnParentChanged(e);
        this.Parent.Resize += new EventHandler(Parent_Resize);
    }
    

    ‘this.Parent’ was sometimes null and so an exception would have been thrown which would have caused the designer to fail.

    Have now fixed this and also tidied up the event hooking so I didn’t leave hooks everywhere. Seems to work fine now. Thanks for your help whoever answered this and deleted their answer for some reason.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that extends Composite and contains a DisclosurePanel at the top-level
I have a class that extends RemoteServiceServlet. This class has several methods, in one
i have class that extends thread and in one of its methodes i added
I have a Java class that extends Thread , it basically looks like the
I have a class that extends AsyncTask , which fetches the gps cordinates from
I have a class that extends Application. The class is fairly extensive. When the
I have a class that extends View. I override the onDraw method and allow
I have a class that extends android.app.Dialog, the layout is done in an xml
i have a class that extends another. when i iterate the current object i
I have a class that extends AsyncTask. In the doInBackground() method, I connect to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.