0

I have been experiencing an issue with my custom TabControl. I cannot remove a Border from the TabControl.

enter image description here

Here is the code of the TabControl.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Drawing;
using System.Windows.Forms;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Drawing.Drawing2D;

namespace GoatUserControls
{
    public partial class GoatTab : TabControl
    {
    public static bool N_PositionMode;
    public static bool N_PlusButton;

    public GoatTab()
    {
        DrawMode = TabDrawMode.OwnerDrawFixed;
        SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.UserPaint | ControlStyles.SupportsTransparentBackColor, true);
        DoubleBuffered = true;
        SizeMode = TabSizeMode.Fixed;
        ItemSize = new System.Drawing.Size(120, 30);
        N_PositionMode = false;
        N_PlusButton = false;
        this.DrawMode = TabDrawMode.OwnerDrawFixed;
        SetWindowTheme(this.Handle, "", "");
        //var tab = new TabPadding(this);
    }

    [DllImportAttribute("uxtheme.dll")]
    private static extern int SetWindowTheme(IntPtr hWnd, string appname, string idlist);

    //All Properties
    [Description("Desides if the Tab Control will display in vertical mode."), Category("Design"), Browsable(true), EditorBrowsable(EditorBrowsableState.Always)]
    public bool VerticalMode{ get { return N_PositionMode; } set { N_PositionMode = value; if (N_PositionMode == true) { SetToVerticalMode(); } if (N_PositionMode == false) { SetToHorrizontalMode(); } }}

    //Method for all of the properties
    private void SetToHorrizontalMode(){ ItemSize = new System.Drawing.Size(120, 30); this.Alignment = TabAlignment.Top; }
    private void SetToVerticalMode(){ ItemSize = new System.Drawing.Size(30, 120); Alignment = TabAlignment.Left; }


    protected override void CreateHandle()
    {
        base.CreateHandle();
        Alignment = TabAlignment.Top;
    }

    protected override void OnPaint(PaintEventArgs e)
    {

        Bitmap B = new Bitmap(Width, Height);

        Graphics G = Graphics.FromImage(B);

        G.Clear(Color.Gainsboro);

        Color NonSelected = Color.FromArgb(62, 62, 62);
        Color Selected = Color.FromArgb(0, 172, 219);

        SolidBrush NOSelect = new SolidBrush(NonSelected);
        SolidBrush ISSelect = new SolidBrush(Selected);

        for (int i = 0; i <= TabCount - 1; i++)
        {
            Rectangle TabRectangle = GetTabRect(i);

            if (i == SelectedIndex)
            {
                //Tab is selected
                G.FillRectangle(ISSelect, TabRectangle);
            }
            else
            {
                //Tab is not selected
                G.FillRectangle(NOSelect, TabRectangle);
            }

            StringFormat sf = new StringFormat();

            sf.LineAlignment = StringAlignment.Center;
            sf.Alignment = StringAlignment.Center;

            Font font = new Font("Segoe UI", 10.0f);

            G.DrawString(TabPages[i].Text, font, Brushes.White, TabRectangle, sf);

            TabPages[i].BackColor = Color.FromArgb(62, 62, 62);
            //TabPages[i].Padding = Point(0, 0);

        }

        e.Graphics.DrawImage(B, 0, 0);
        G.Dispose();
        B.Dispose();
        base.OnPaint(e);

    }

}
}

I think the Border is a background of the control. So most likely the question is how can I remove the background of a control. Do you guys have any ideas?

StepUp
  • 36,391
  • 15
  • 88
  • 148
Braydel
  • 21
  • 1
  • 6
  • What are you targetting: Winforms, WPF, ASP..? __Always__ tag your question correctly. – TaW May 05 '16 at 14:33
  • 1
    See [TabControl and borders visual glitch](http://stackoverflow.com/a/7785745/719186) – LarsTech May 05 '16 at 14:50
  • There isn't much you can do with TabControl, only the tab content is owner-draw. You've got SetWindowTheme() already, that at least bypasses the visual style renderer problems that Lars is talking about. Next thing you could do is make it skinny enough so only the tab strip is visible and use, say, panels or user controls to resurrect the tab pages. Next thing you could do is just use a completely different control, replacing TabControl is a pretty popular codeproject.com topic. – Hans Passant May 05 '16 at 15:04
  • If you're using WinForms, [this thread](http://stackoverflow.com/questions/6953487/hide-tab-header-on-c-sharp-tabcontrol) might be able to help you. – aleonj May 05 '16 at 15:48
  • I am using winform, LarsTech I did that before and it will start to remove the tab page at the top when I extend it. Hans and aleonj ill try your idea and if that doesn't work ill post back soon – Braydel May 06 '16 at 00:09
  • So I tried Lars idea and that didn't work. And I don't really know how the thread from aleonj actually works. You have the panel but how does that have multiple of pages and how would I make the tab control manager. Also I think replacing TabControl class and just making my own control would be better. So how would I be able to do that? – Braydel May 06 '16 at 00:37

0 Answers0