C#如何删除自定义TabControl边框或标题

时间:2016-05-05 14:15:08

标签: c# winforms tabcontrol

我的自定义git diff 0dae34e 769ffr330c 遇到了问题。我无法从TabControl删除Border

enter image description here

以下是TabControl的代码。

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); } } } 是控件的背景。所以最有可能的问题是如何删除控件的背景。你们有什么想法吗?

0 个答案:

没有答案