Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement