C# Удалить границы TabControl или установить другой цвет
Я переделал TabControl, на расположение вкладок слева, путем создания компонента. Но я не могу поменять цвет или стереть границы, выделил на скриншоте.
Вот полный код
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace TestControlTabControl
{
public partial class UserTabControl: TabControl
{
public UserTabControl()
{
InitializeComponent();
}
private void InitializeComponent()
{
SizeMode = TabSizeMode.Fixed;
Alignment = TabAlignment.Left;
DrawMode = TabDrawMode.OwnerDrawFixed;
ItemSize = new Size(30, 60);
}
protected override void OnDrawItem(DrawItemEventArgs e)
{
base.OnDrawItem(e);
e.Graphics.SetClip(e.Bounds);
string text = TabPages[e.Index].Text;
SizeF sz = e.Graphics.MeasureString(text, e.Font);
bool bSelected = (e.State & DrawItemState.Selected) == DrawItemState.Selected;
Color customColor = Color.FromArgb(100, Color.FromArgb(2, 27, 30));
SolidBrush shadowBrush = new SolidBrush(customColor);
// using (SolidBrush b = new SolidBrush(bSelected ? SystemColors.Highlight : SystemColors.Control))
// e.Graphics.FillRectangle(shadowBrush, e.Bounds);
Pen p = new Pen(Color.Red);
e.Graphics.DrawRectangle(p, this.GetTabRect(this.SelectedIndex));
using (SolidBrush b = new SolidBrush(bSelected ? SystemColors.Menu: SystemColors.Menu))
e.Graphics.FillRectangle(shadowBrush, e.Bounds);
using (SolidBrush b = new SolidBrush(bSelected ? SystemColors.HighlightText : SystemColors.ControlText))
e.Graphics.DrawString(text, e.Font, b, e.Bounds.X + 2, e.Bounds.Y + (e.Bounds.Height - sz.Height) / 2);
if (SelectedIndex == e.Index)
{
e.DrawFocusRectangle();
}
else
{
e.Graphics.FillRectangle(shadowBrush, this.GetTabRect(this.SelectedIndex));
}
e.Graphics.ResetClip();
}
}
}
