0Hawk0

Onlykl Theme

Dec 13th, 2014
552
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 10.65 KB | None | 0 0
  1. Imports System.Drawing.Drawing2D
  2. Imports System.ComponentModel
  3.  
  4. Module ThemeModule
  5.  
  6.     Friend Const SLOPE As Integer = 4
  7.  
  8.     Friend g As Graphics
  9.  
  10.     Friend Enum MouseState
  11.         None
  12.         Over
  13.         Down
  14.     End Enum
  15.  
  16.     Public Sub DrawCenteredString(g As Graphics, text As String, font As Font, brush As Brush, rect As Rectangle, Optional xOffset As Integer = 0, Optional yOffset As Integer = 0)
  17.  
  18.         Dim textSize As SizeF = g.MeasureString(text, font)
  19.         Dim textX As Integer = rect.X + (rect.Width / 2) - (textSize.Width / 2) + xOffset
  20.         Dim textY As Integer = rect.Y + (rect.Height / 2) - (textSize.Height / 2) + yOffset
  21.  
  22.         g.DrawString(text, font, brush, textX, textY)
  23.  
  24.     End Sub
  25.  
  26. End Module
  27.  
  28. Class OnlyGroupBox
  29.     Inherits ContainerControl
  30.  
  31.     Sub New()
  32.  
  33.         SetStyle(DirectCast(139286, ControlStyles), True)
  34.         SetStyle(ControlStyles.Selectable, False)
  35.  
  36.         Size = New Size(400, 300)
  37.  
  38.         backBrush = New SolidBrush(Color.FromArgb(0, 70, 90))
  39.         borderPen = New Pen(Color.FromArgb(90, 135, 140))
  40.         coverPen = New Pen(Color.FromArgb(0, 70, 90))
  41.  
  42.     End Sub
  43.  
  44.     Private backBrush As SolidBrush
  45.     Private borderPen As Pen
  46.     Private coverPen As Pen
  47.  
  48.     Protected Overrides Sub OnPaint(e As PaintEventArgs)
  49.  
  50.         g = e.Graphics
  51.         g.Clear(Parent.BackColor)
  52.         g.SmoothingMode = SmoothingMode.AntiAlias
  53.  
  54.         g.DrawRectangle(borderPen, New Rectangle(0, 0, Width - 1, Height - 1))
  55.  
  56.         g.DrawLine(coverPen, New Point(0, Height / 8), New Point(0, Height / 1.8))
  57.         g.DrawLine(coverPen, New Point(Width / 20, 0), New Point(Width - (Width / 8), 0))
  58.         g.DrawLine(coverPen, New Point(Width - 1, Height / 5), New Point(Width - 1, Height / 1.25))
  59.  
  60.  
  61.     End Sub
  62.  
  63. End Class
  64.  
  65. Class OnlyButton
  66.     Inherits Control
  67.  
  68.     Private state As MouseState
  69.  
  70.     Private textSize As SizeF
  71.     Private textX, textY As Integer
  72.  
  73.     Sub New()
  74.  
  75.         SetStyle(DirectCast(139286, ControlStyles), True)
  76.         SetStyle(ControlStyles.Selectable, False)
  77.  
  78.         Cursor = Cursors.Hand
  79.         Font = New Font(Font.FontFamily, 10)
  80.         Size = New Size(120, 30)
  81.  
  82.         textBrush = New SolidBrush(Color.FromArgb(20, 60, 70))
  83.         overBrush = New SolidBrush(Color.FromArgb(40, 0, 70, 90))
  84.         downBrush = New SolidBrush(Color.FromArgb(100, 0, 70, 90))
  85.  
  86.     End Sub
  87.  
  88.     Private boundsRect As Rectangle
  89.  
  90.     Private textBrush As SolidBrush
  91.     Private overBrush, downBrush As SolidBrush
  92.  
  93.     Protected Overrides Sub OnPaint(e As PaintEventArgs)
  94.  
  95.         g = e.Graphics
  96.         g.SmoothingMode = SmoothingMode.AntiAlias
  97.  
  98.         boundsRect = New Rectangle(0, 0, Width, Height)
  99.  
  100.         g.FillRectangle(Brushes.WhiteSmoke, boundsRect)
  101.  
  102.         If state = MouseState.Over Then
  103.             g.FillRectangle(overBrush, boundsRect)
  104.         ElseIf state = MouseState.Down Then
  105.             g.FillRectangle(downBrush, boundsRect)
  106.         End If
  107.  
  108.         DrawCenteredString(g, Text, Font, textBrush, boundsRect, 0, 1)
  109.  
  110.     End Sub
  111.  
  112.     Protected Overrides Sub OnMouseEnter(e As EventArgs)
  113.         state = MouseState.Over
  114.         Invalidate()
  115.         MyBase.OnMouseEnter(e)
  116.     End Sub
  117.  
  118.     Protected Overrides Sub OnMouseLeave(e As EventArgs)
  119.         state = MouseState.None
  120.         Invalidate()
  121.         MyBase.OnMouseLeave(e)
  122.     End Sub
  123.  
  124.     Protected Overrides Sub OnMouseDown(e As MouseEventArgs)
  125.         state = MouseState.Down
  126.         Invalidate()
  127.         MyBase.OnMouseDown(e)
  128.     End Sub
  129.  
  130.     Protected Overrides Sub OnMouseUp(e As MouseEventArgs)
  131.         state = MouseState.Over
  132.         Invalidate()
  133.         MyBase.OnMouseUp(e)
  134.     End Sub
  135.  
  136.     Protected Overrides Sub OnTextChanged(e As EventArgs)
  137.         Invalidate()
  138.         MyBase.OnTextChanged(e)
  139.     End Sub
  140.  
  141. End Class
  142.  
  143. Class OnlyMessageBox
  144.     Inherits Control
  145.  
  146.     Sub New()
  147.  
  148.         SetStyle(DirectCast(139286, ControlStyles), True)
  149.         SetStyle(ControlStyles.Selectable, False)
  150.  
  151.         Font = New Font(Font.FontFamily, 10)
  152.         Size = New Size(400, 44)
  153.  
  154.         textBrush = New SolidBrush(Color.FromArgb(100, 140, 150))
  155.  
  156.     End Sub
  157.  
  158.     Private boundsRect As Rectangle
  159.  
  160.     Private textBrush As SolidBrush
  161.  
  162.     Protected Overrides Sub OnPaint(e As PaintEventArgs)
  163.  
  164.         g = e.Graphics
  165.         g.Clear(Color.FromArgb(25, 90, 105))
  166.  
  167.         boundsRect = New Rectangle(0, 0, Width - 1, Height - 1)
  168.         DrawCenteredString(g, Text, Font, textBrush, boundsRect, 0, 1)
  169.  
  170.     End Sub
  171.  
  172.     Protected Overrides Sub OnTextChanged(e As EventArgs)
  173.         Invalidate()
  174.         MyBase.OnTextChanged(e)
  175.     End Sub
  176.  
  177. End Class
  178.  
  179. <DefaultEvent("TextChanged")> Class OnlyTextBox
  180.     Inherits Control
  181.  
  182.     Private base As TextBox
  183.  
  184.     Private _maxLength As Integer
  185.     Private _readOnly As Boolean
  186.     Private _useSystemPasswordChar As Boolean
  187.     Private _image As Image
  188.  
  189.     Public Property MaxLength() As Integer
  190.         Get
  191.             Return _maxLength
  192.         End Get
  193.         Set(ByVal value As Integer)
  194.             _maxLength = value
  195.             If base IsNot Nothing Then
  196.                 base.MaxLength = value
  197.             End If
  198.         End Set
  199.     End Property
  200.  
  201.     Public Property [ReadOnly]() As Boolean
  202.         Get
  203.             Return _readOnly
  204.         End Get
  205.         Set(ByVal value As Boolean)
  206.             _readOnly = value
  207.             If base IsNot Nothing Then
  208.                 base.ReadOnly = value
  209.             End If
  210.         End Set
  211.     End Property
  212.  
  213.     Public Property UseSystemPasswordChar() As Boolean
  214.         Get
  215.             Return _useSystemPasswordChar
  216.         End Get
  217.         Set(ByVal value As Boolean)
  218.             _useSystemPasswordChar = value
  219.             If base IsNot Nothing Then
  220.                 base.UseSystemPasswordChar = value
  221.             End If
  222.         End Set
  223.     End Property
  224.  
  225.     Public Property Image As Image
  226.         Get
  227.             Return _image
  228.         End Get
  229.         Set(value As Image)
  230.             _image = value
  231.             ApplySizing()
  232.             Invalidate()
  233.         End Set
  234.     End Property
  235.  
  236.     Public Overrides Property Text() As String
  237.         Get
  238.             Return MyBase.Text
  239.         End Get
  240.         Set(ByVal value As String)
  241.             MyBase.Text = value
  242.             If base IsNot Nothing Then
  243.                 base.Text = value
  244.             End If
  245.         End Set
  246.     End Property
  247.  
  248.     Public Overrides Property Font() As Font
  249.         Get
  250.             Return MyBase.Font
  251.         End Get
  252.         Set(ByVal value As Font)
  253.             MyBase.Font = value
  254.             If base IsNot Nothing Then
  255.                 base.Font = value
  256.                 base.Location = New Point(3, 5)
  257.                 base.Width = Width - 6
  258.             End If
  259.         End Set
  260.     End Property
  261.  
  262.     Protected Overrides Sub OnCreateControl()
  263.         MyBase.OnCreateControl()
  264.         If Not Controls.Contains(base) Then
  265.             Controls.Add(base)
  266.         End If
  267.     End Sub
  268.  
  269.     Sub New()
  270.  
  271.         SetStyle(DirectCast(139286, ControlStyles), True)
  272.         SetStyle(ControlStyles.Selectable, False)
  273.  
  274.         Cursor = Cursors.IBeam
  275.         Font = New Font("Arial", 10)
  276.  
  277.         MaxLength = 32767
  278.  
  279.         base = New TextBox
  280.         base.BackColor = Color.FromArgb(10, 75, 95)
  281.         base.Font = Font
  282.         base.Text = Text
  283.         base.ForeColor = Color.WhiteSmoke
  284.         base.MaxLength = _maxLength
  285.         base.ReadOnly = _readOnly
  286.         base.UseSystemPasswordChar = _useSystemPasswordChar
  287.         base.BorderStyle = BorderStyle.None
  288.         base.Location = New Point(10, 8)
  289.         base.Width = Width - 10
  290.  
  291.         Height = base.Height + 13
  292.  
  293.         backBrush = New SolidBrush(Color.FromArgb(10, 75, 95))
  294.         borderPen = New Pen(Color.FromArgb(70, 120, 135))
  295.  
  296.         AddHandler base.TextChanged, AddressOf OnBaseTextChanged
  297.         AddHandler base.KeyDown, AddressOf OnBaseKeyDown
  298.  
  299.     End Sub
  300.  
  301.     Private boundsRect As Rectangle
  302.     Private imageRect As Rectangle
  303.  
  304.     Private backBrush As SolidBrush
  305.     Private borderPen As Pen
  306.  
  307.     Protected Overrides Sub OnPaint(e As PaintEventArgs)
  308.  
  309.         g = e.Graphics
  310.         g.Clear(Parent.BackColor)
  311.         g.SmoothingMode = SmoothingMode.AntiAlias
  312.  
  313.         boundsRect = New Rectangle(0, 0, Width - 1, Height - 1)
  314.         g.FillRectangle(backBrush, boundsRect)
  315.         g.DrawRectangle(borderPen, boundsRect)
  316.  
  317.         If _image IsNot Nothing Then
  318.             imageRect = New Rectangle(Width - 27, 6, 20, 20)
  319.             g.DrawImage(_image, imageRect)
  320.         End If
  321.  
  322.     End Sub
  323.  
  324.     Private Sub OnBaseTextChanged(ByVal s As Object, ByVal e As EventArgs)
  325.         Text = base.Text
  326.     End Sub
  327.  
  328.     Private Sub OnBaseKeyDown(ByVal s As Object, ByVal e As KeyEventArgs)
  329.         If e.Control AndAlso e.KeyCode = Keys.A Then
  330.             base.SelectAll()
  331.             e.SuppressKeyPress = True
  332.         End If
  333.     End Sub
  334.  
  335.     Private Sub ApplySizing()
  336.         base.Location = New Point(10, 8)
  337.         If _image IsNot Nothing Then
  338.             base.Width = Width - 44
  339.         Else
  340.             base.Width = Width - 20
  341.         End If
  342.         Height = base.Height + 16
  343.     End Sub
  344.  
  345.     Protected Overrides Sub OnResize(ByVal e As EventArgs)
  346.         ApplySizing()
  347.         MyBase.OnResize(e)
  348.     End Sub
  349.  
  350.     Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
  351.         base.SelectionStart = base.TextLength
  352.         base.Focus()
  353.         MyBase.OnMouseDown(e)
  354.     End Sub
  355.  
  356. End Class
  357.  
  358. Class OnlyWarningMessage
  359.     Inherits Control
  360.  
  361.     Private _image As Image
  362.  
  363.     Public Property Image As Image
  364.         Get
  365.             Return _image
  366.         End Get
  367.         Set(value As Image)
  368.             _image = value
  369.             Invalidate()
  370.         End Set
  371.     End Property
  372.  
  373.     Sub New()
  374.  
  375.         SetStyle(DirectCast(139286, ControlStyles), True)
  376.         SetStyle(ControlStyles.Selectable, False)
  377.  
  378.         Font = New Font(Font.FontFamily, 9)
  379.         Size = New Size(140, 26)
  380.  
  381.     End Sub
  382.  
  383.     Private imageRect As Rectangle
  384.     Private boundsRect As Rectangle
  385.  
  386.     Protected Overrides Sub OnPaint(e As PaintEventArgs)
  387.  
  388.         g = e.Graphics
  389.         g.Clear(Parent.BackColor)
  390.         g.SmoothingMode = SmoothingMode.AntiAlias
  391.  
  392.         If _image IsNot Nothing Then
  393.             imageRect = New Rectangle(0, (Height / 2) - 10, 20, 20)
  394.             g.DrawImage(_image, imageRect)
  395.         End If
  396.  
  397.         g.DrawString(Text, Font, Brushes.WhiteSmoke, New Point(24, (Height / 2) - g.MeasureString(Text, Font).Height / 2))
  398.  
  399.     End Sub
  400.  
  401.     Protected Overrides Sub OnTextChanged(e As EventArgs)
  402.         Invalidate()
  403.         MyBase.OnTextChanged(e)
  404.     End Sub
  405.  
  406. End Class
Advertisement
Add Comment
Please, Sign In to add comment