Advertisement
Guest User

Untitled

a guest
May 5th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.24 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Drawing;
  5. using System.Windows.Forms;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.ComponentModel;
  9. using System.Runtime.InteropServices;
  10. using System.Drawing.Drawing2D;
  11.  
  12. namespace GoatUserControls
  13. {
  14. public partial class GoatTab : TabControl
  15. {
  16. public static bool N_PositionMode;
  17. public static bool N_PlusButton;
  18.  
  19. public GoatTab()
  20. {
  21. DrawMode = TabDrawMode.OwnerDrawFixed;
  22. SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.UserPaint | ControlStyles.SupportsTransparentBackColor, true);
  23. DoubleBuffered = true;
  24. SizeMode = TabSizeMode.Fixed;
  25. ItemSize = new System.Drawing.Size(120, 30);
  26. N_PositionMode = false;
  27. N_PlusButton = false;
  28. this.DrawMode = TabDrawMode.OwnerDrawFixed;
  29. SetWindowTheme(this.Handle, "", "");
  30. //var tab = new TabPadding(this);
  31. }
  32.  
  33. [DllImportAttribute("uxtheme.dll")]
  34. private static extern int SetWindowTheme(IntPtr hWnd, string appname, string idlist);
  35.  
  36. //All Properties
  37. [Description("Desides if the Tab Control will display in vertical mode."), Category("Design"), Browsable(true), EditorBrowsable(EditorBrowsableState.Always)]
  38. public bool VerticalMode{ get { return N_PositionMode; } set { N_PositionMode = value; if (N_PositionMode == true) { SetToVerticalMode(); } if (N_PositionMode == false) { SetToHorrizontalMode(); } }}
  39.  
  40. //Method for all of the properties
  41. private void SetToHorrizontalMode(){ ItemSize = new System.Drawing.Size(120, 30); this.Alignment = TabAlignment.Top; }
  42. private void SetToVerticalMode(){ ItemSize = new System.Drawing.Size(30, 120); Alignment = TabAlignment.Left; }
  43.  
  44.  
  45. protected override void CreateHandle()
  46. {
  47. base.CreateHandle();
  48. Alignment = TabAlignment.Top;
  49. }
  50.  
  51. protected override void OnPaint(PaintEventArgs e)
  52. {
  53.  
  54. Bitmap B = new Bitmap(Width, Height);
  55.  
  56. Graphics G = Graphics.FromImage(B);
  57.  
  58. G.Clear(Color.Gainsboro);
  59.  
  60. Color NonSelected = Color.FromArgb(62, 62, 62);
  61. Color Selected = Color.FromArgb(0, 172, 219);
  62.  
  63. SolidBrush NOSelect = new SolidBrush(NonSelected);
  64. SolidBrush ISSelect = new SolidBrush(Selected);
  65.  
  66. for (int i = 0; i <= TabCount - 1; i++)
  67. {
  68. Rectangle TabRectangle = GetTabRect(i);
  69.  
  70. if (i == SelectedIndex)
  71. {
  72. //Tab is selected
  73. G.FillRectangle(ISSelect, TabRectangle);
  74. }
  75. else
  76. {
  77. //Tab is not selected
  78. G.FillRectangle(NOSelect, TabRectangle);
  79. }
  80.  
  81. StringFormat sf = new StringFormat();
  82.  
  83. sf.LineAlignment = StringAlignment.Center;
  84. sf.Alignment = StringAlignment.Center;
  85.  
  86. Font font = new Font("Segoe UI", 10.0f);
  87.  
  88. G.DrawString(TabPages[i].Text, font, Brushes.White, TabRectangle, sf);
  89.  
  90. TabPages[i].BackColor = Color.FromArgb(62, 62, 62);
  91. //TabPages[i].Padding = Point(0, 0);
  92.  
  93. }
  94.  
  95. e.Graphics.DrawImage(B, 0, 0);
  96. G.Dispose();
  97. B.Dispose();
  98. base.OnPaint(e);
  99.  
  100. }
  101.  
  102. }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement