Euras

Untitled

Aug 2nd, 2014
492
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 17.42 KB | None | 0 0
  1. Imports System.Drawing.Drawing2D
  2. Imports System.ComponentModel
  3. Imports System.Runtime.InteropServices
  4.  
  5. '-------------------------
  6. 'Theme:          EasyColour
  7. 'Creator:        Euras
  8. 'Version:        1.0
  9. 'Created:        02/08/14
  10. 'Website:        eurashd.com
  11. '-------------------------
  12.  
  13. Public Class EC_Theme : Inherits ContainerControl
  14.  
  15.     <DllImportAttribute("user32.dll")> _
  16.     Public Shared Function SendMessage(hWnd As IntPtr, Msg As Integer, wParam As Integer, lParam As Integer) As Integer
  17.     End Function
  18.     <DllImportAttribute("user32.dll")> _
  19.     Public Shared Function ReleaseCapture() As Boolean
  20.     End Function
  21.     Public Const WM_NCLBUTTONDOWN As Integer = &HA1
  22.     Public Const HT_CAPTION As Integer = &H2
  23.  
  24.     Protected NotOverridable Overrides Sub OnHandleCreated(e As EventArgs)
  25.         MyBase.Dock = DockStyle.Fill
  26.         ForeColor = Color.White
  27.         MyBase.OnHandleCreated(e)
  28.     End Sub
  29.  
  30.     Private _IsParentForm As Boolean
  31.  
  32.     Protected Property IsParentForm() As Boolean
  33.         Get
  34.             Return _IsParentForm
  35.         End Get
  36.         Set(value As Boolean)
  37.             _IsParentForm = value
  38.         End Set
  39.     End Property
  40.  
  41.     Private _Transparent As Boolean
  42.     Public Property Transparent() As Boolean
  43.         Get
  44.             Return _Transparent
  45.         End Get
  46.         Set(value As Boolean)
  47.             _Transparent = value
  48.             If Not IsHandleCreated Then
  49.                 Return
  50.                 SetStyle(ControlStyles.Opaque, Not value)
  51.                 SetStyle(ControlStyles.SupportsTransparentBackColor, value)
  52.                 Invalidate()
  53.             End If
  54.         End Set
  55.     End Property
  56.  
  57.     Protected Overrides Sub OnParentChanged(e As System.EventArgs)
  58.         MyBase.OnParentChanged(e)
  59.         If Parent Is Nothing Then
  60.             Return
  61.             _IsParentForm = TypeOf Parent Is Form
  62.         End If
  63.         If _IsParentForm Then
  64.             ParentForm.FormBorderStyle = _BorderStyle
  65.         End If
  66.     End Sub
  67.  
  68.     Private _BorderStyle As FormBorderStyle
  69.     Public Property BorderStyle() As FormBorderStyle
  70.         Get
  71.             If _IsParentForm Then
  72.                 Return ParentForm.FormBorderStyle
  73.             Else
  74.                 Return _BorderStyle
  75.             End If
  76.         End Get
  77.         Set(value As FormBorderStyle)
  78.             _BorderStyle = value
  79.             If _IsParentForm Then
  80.                 ParentForm.FormBorderStyle = value
  81.             End If
  82.         End Set
  83.     End Property
  84.  
  85.     Protected Overrides ReadOnly Property CreateParams As System.Windows.Forms.CreateParams
  86.         Get
  87.             Const CS_DROPSHADOW As Integer = &H20000
  88.             Dim cp As CreateParams = MyBase.CreateParams
  89.             cp.ClassStyle = cp.ClassStyle Or CS_DROPSHADOW
  90.             Return cp
  91.         End Get
  92.     End Property
  93.  
  94.     Protected Overrides Sub OnMouseDown(e As System.Windows.Forms.MouseEventArgs)
  95.         MyBase.OnMouseDown(e)
  96.         If e.Button = MouseButtons.Left Then
  97.             ReleaseCapture()
  98.             SendMessage(Parent.Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0)
  99.         End If
  100.     End Sub
  101.  
  102.     Protected Overrides Sub OnPaint(e As System.Windows.Forms.PaintEventArgs)
  103.         MyBase.OnPaint(e)
  104.         Dim g As Graphics = e.Graphics
  105.         g.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
  106.         g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
  107.         g.TextRenderingHint = Drawing.Text.TextRenderingHint.ClearTypeGridFit
  108.  
  109.         g.FillRectangle(New SolidBrush(Color.FromArgb(75, 0, 0, 0)), New Rectangle(-1, -1, Width + 1, 25))
  110.         Dim icon As Image = My.Resources.icon
  111.         Dim iSize As Size = New Size(16, 16)
  112.         g.DrawImage(icon, 5, 5, 16, 16)
  113.         g.DrawString(Text, Font, New SolidBrush(ForeColor), New Point(25, 5), StringFormat.GenericDefault)
  114.         g.Dispose()
  115.     End Sub
  116. End Class
  117.  
  118. Class EC_Button
  119.     Inherits Control
  120.     Dim isHover As Boolean
  121.     Dim _ButtonText As String
  122.     Dim _Image As Image
  123.     Dim _ImageSize As Size
  124.  
  125.     Public Sub New()
  126.         SetStyle(ControlStyles.SupportsTransparentBackColor, True)
  127.         BackColor = Color.Transparent
  128.         Cursor = Cursors.Hand
  129.     End Sub
  130.  
  131.     Protected Overrides Sub OnMouseEnter(e As EventArgs)
  132.         MyBase.OnMouseEnter(e)
  133.         isHover = True
  134.         Invalidate()
  135.     End Sub
  136.  
  137.     Protected Overrides Sub OnMouseLeave(e As EventArgs)
  138.         MyBase.OnMouseLeave(e)
  139.         isHover = False
  140.         Invalidate()
  141.     End Sub
  142.  
  143.     <Category("Appearance")> _
  144.     Public Overrides Property Text() As String
  145.         Get
  146.             Return _ButtonText
  147.         End Get
  148.         Set(value As String)
  149.             _ButtonText = value
  150.         End Set
  151.     End Property
  152.  
  153.     <Category("Appearance")> _
  154.     Public Property Image() As Image
  155.         Get
  156.             Return _Image
  157.         End Get
  158.         Set(value As Image)
  159.             _Image = value
  160.         End Set
  161.     End Property
  162.  
  163.     <Category("Appearance")> _
  164.     Public Property ImageSize() As Size
  165.         Get
  166.             Return _ImageSize
  167.         End Get
  168.         Set(value As Size)
  169.             _ImageSize = value
  170.         End Set
  171.     End Property
  172.  
  173.     Protected Overrides Sub OnPaint(e As PaintEventArgs)
  174.         MyBase.OnPaint(e)
  175.         Dim g As Graphics = e.Graphics
  176.         g.InterpolationMode = InterpolationMode.HighQualityBicubic
  177.  
  178.         Dim s As SizeF = g.MeasureString(_ButtonText, Font)
  179.         Dim x As Integer = ClientSize.Width
  180.         Dim y As Integer = ClientSize.Height
  181.  
  182.         g.FillRectangle(New SolidBrush(Color.FromArgb(120, 0, 0, 0)), New Rectangle(0, y / 2, x - 1, y - 1))
  183.         g.FillRectangle(New SolidBrush(Color.FromArgb(80, 0, 0, 0)), New Rectangle(0, 0, x - 1, y / 2))
  184.  
  185.         If Text Is Nothing Then
  186.             _ButtonText = Name
  187.         End If
  188.  
  189.         g.DrawString(_ButtonText, Font, New SolidBrush(Color.White), (x - s.Width) / 2, (y - s.Height) / 2)
  190.  
  191.         If _Image IsNot Nothing Then
  192.             Dim imgX As Integer = _ImageSize.Width
  193.             Dim imgY As Integer = _ImageSize.Height
  194.  
  195.             If _ImageSize.IsEmpty Then
  196.                 g.DrawImage(_Image, New Rectangle(5, (y - imgY) / 2, 16, 16))
  197.             Else
  198.                 g.DrawImage(_Image, New Rectangle(5, (y - imgY) / 2, imgX, imgY))
  199.             End If
  200.         End If
  201.  
  202.         If isHover Then
  203.             g.FillRectangle(New SolidBrush(Color.FromArgb(25, 0, 0, 0)), New Rectangle(0, 0, x, y))
  204.         End If
  205.  
  206.         g.Dispose()
  207.     End Sub
  208. End Class
  209.  
  210. Class EC_CheckBox
  211.     Inherits Control
  212.     Private _Checked As Boolean
  213.  
  214.     Public Sub New()
  215.         SetStyle(ControlStyles.SupportsTransparentBackColor, True)
  216.         BackColor = Color.Transparent
  217.         Size = New Size(20, 20)
  218.         MaximumSize = Size
  219.         MinimumSize = Size
  220.         Cursor = Cursors.Hand
  221.     End Sub
  222.  
  223.     Protected Overrides Sub OnMouseClick(e As MouseEventArgs)
  224.         If _Checked Then
  225.             _Checked = False
  226.         ElseIf Not _Checked Then
  227.             _Checked = True
  228.         End If
  229.         Invalidate()
  230.         MyBase.OnMouseClick(e)
  231.     End Sub
  232.  
  233.     Public Property Checked() As Boolean
  234.         Get
  235.             Return _Checked
  236.         End Get
  237.         Set(value As Boolean)
  238.             _Checked = value
  239.         End Set
  240.     End Property
  241.  
  242.     Protected Overrides Sub OnPaint(e As PaintEventArgs)
  243.         MyBase.OnPaint(e)
  244.         Dim g As Graphics = e.Graphics
  245.         g.SmoothingMode = SmoothingMode.HighQuality
  246.         g.InterpolationMode = InterpolationMode.HighQualityBicubic
  247.         Dim x As Integer = ClientSize.Width
  248.         Dim y As Integer = ClientSize.Height
  249.  
  250.         g.FillEllipse(New SolidBrush(Color.FromArgb(25, 0, 0, 0)), New Rectangle(0, 0, x - 1, y - 1))
  251.         g.FillEllipse(New SolidBrush(Color.FromArgb(75, 255, 255, 255)), New Rectangle(3, 3, x - 7, y - 7))
  252.  
  253.         If _Checked Then
  254.             g.FillEllipse(New SolidBrush(Color.FromArgb(100, 0, 0, 0)), New RectangleF(5, 5, (x / 2) - 1, (y / 2) - 1))
  255.         End If
  256.  
  257.         g.Dispose()
  258.     End Sub
  259. End Class
  260.  
  261. Class EC_Panel
  262.     Inherits Panel
  263.     Public _PanelText As String
  264.  
  265.     <Category("Appearance")> _
  266.     Public Property PanelText() As String
  267.         Get
  268.             Return _PanelText
  269.         End Get
  270.         Set(value As String)
  271.             _PanelText = value
  272.         End Set
  273.     End Property
  274.  
  275.     Protected Overrides Sub OnPaint(e As PaintEventArgs)
  276.         MyBase.OnPaint(e)
  277.         Dim g As Graphics = e.Graphics
  278.         g.SmoothingMode = SmoothingMode.HighQuality
  279.         g.InterpolationMode = InterpolationMode.HighQualityBicubic
  280.         g.TextRenderingHint = Drawing.Text.TextRenderingHint.ClearTypeGridFit
  281.         Dim x As Integer = ClientSize.Width
  282.         Dim y As Integer = ClientSize.Height
  283.  
  284.         g.FillRectangle(New SolidBrush(Color.FromArgb(25, 0, 0, 0)), New Rectangle(0, 0, x, 25))
  285.  
  286.         If PanelText Is Nothing Then
  287.             _PanelText = Name
  288.         End If
  289.  
  290.         g.FillRectangle(New SolidBrush(Color.FromArgb(50, 0, 0, 0)), New Rectangle(0, 0, x, y))
  291.         g.DrawString(_PanelText, Font, New SolidBrush(Color.White), New Point(5, 5))
  292.  
  293.         g.Dispose()
  294.     End Sub
  295. End Class
  296.  
  297. Class EC_Tabs
  298.     Inherits TabControl
  299.     ' Initialize
  300.     Public Sub New()
  301.         DrawMode = TabDrawMode.OwnerDrawFixed
  302.         SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.DoubleBuffer Or ControlStyles.ResizeRedraw Or ControlStyles.UserPaint, True)
  303.         DoubleBuffered = True
  304.         Dock = DockStyle.Bottom
  305.         SizeMode = TabSizeMode.Normal
  306.         ItemSize = New Size(100, 20)
  307.     End Sub
  308.  
  309.     ' Tabs Back Color Property
  310.     Private m_Backcolor As Color = Color.Empty
  311.     <Browsable(True)> _
  312.     Public Overrides Property BackColor() As Color
  313.         Get
  314.             If m_Backcolor.Equals(Color.Empty) Then
  315.                 If Parent Is Nothing Then
  316.                     Return Control.DefaultBackColor
  317.                 Else
  318.                     Return Parent.BackColor
  319.                 End If
  320.             End If
  321.             Return m_Backcolor
  322.         End Get
  323.         Set(value As Color)
  324.             If m_Backcolor.Equals(value) Then
  325.                 Return
  326.             End If
  327.             m_Backcolor = value
  328.             Invalidate()
  329.             MyBase.OnBackColorChanged(EventArgs.Empty)
  330.         End Set
  331.     End Property
  332.  
  333.     Public Function ShouldSerializeBackColor() As Boolean
  334.         Return Not m_Backcolor.Equals(Color.Empty)
  335.     End Function
  336.  
  337.     Public Overrides Sub ResetBackColor()
  338.         m_Backcolor = Color.Empty
  339.         Invalidate()
  340.     End Sub
  341.  
  342.     Protected Overrides Sub OnPaint(e As PaintEventArgs)
  343.         MyBase.OnPaint(e)
  344.         Dim g As Graphics = e.Graphics
  345.         g.Clear(BackColor)
  346.  
  347.         g.SmoothingMode = SmoothingMode.HighQuality
  348.         g.InterpolationMode = InterpolationMode.HighQualityBicubic
  349.  
  350.         ' Apply Colouring To Each Tab Page
  351.         For i As Integer = 0 To TabPages.Count - 1
  352.             Dim rect As Rectangle = GetTabRect(i)
  353.             Dim r As New Rectangle(GetTabRect(i).X + 10, GetTabRect(i).Y + 3, 100, 20)
  354.             If SelectedTab Is TabPages(i) Then
  355.                 g.FillRectangle(New SolidBrush(Color.FromArgb(75, 0, 0, 0)), rect)
  356.             Else
  357.                 g.FillRectangle(New SolidBrush(Color.FromArgb(25, 0, 0, 0)), rect)
  358.             End If
  359.  
  360.             ' Draw Tab Page Text
  361.             g.DrawString(TabPages(i).Text, Font, New SolidBrush(Color.White), DirectCast(r, Rectangle))
  362.             TabPages(i).UseVisualStyleBackColor = False
  363.         Next
  364.     End Sub
  365. End Class
  366.  
  367. Class EC_Notification
  368.     Inherits UserControl
  369.     Private _Text As String
  370.  
  371.     ' Initialize
  372.     Public Sub New()
  373.         SetStyle(ControlStyles.OptimizedDoubleBuffer Or ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint, True)
  374.         DoubleBuffered = True
  375.         BackColor = Color.Transparent
  376.         Size = New Size(200, 25)
  377.     End Sub
  378.  
  379.     ' Notification Property
  380.     <Category("Appearance")> _
  381.     Public Property Notification() As String
  382.         Get
  383.             Return _Text
  384.         End Get
  385.         Set(value As String)
  386.             _Text = value
  387.         End Set
  388.     End Property
  389.  
  390.     Protected Overrides Sub OnPaint(e As PaintEventArgs)
  391.         MyBase.OnPaint(e)
  392.         Dim g As Graphics = e.Graphics
  393.  
  394.         Dim s As SizeF = g.MeasureString(_Text, Font)
  395.         g.SmoothingMode = SmoothingMode.HighQuality
  396.         g.InterpolationMode = InterpolationMode.HighQualityBicubic
  397.         Dim x As Integer = ClientSize.Width
  398.         Dim y As Integer = ClientSize.Height
  399.  
  400.         ' Notification Shadow
  401.         g.FillRectangle(New SolidBrush(Color.FromArgb(35, Color.Black)), New Rectangle(5, 5, x, y))
  402.         ' Notification Fill
  403.         g.FillRectangle(New SolidBrush(Color.White), New Rectangle(0, 0, x - 5, y - 5))
  404.         ' Notification Text
  405.         g.DrawString(_Text, Font, New SolidBrush(Color.Black), New PointF(5, ((y - 5) - s.Height) / 2))
  406.     End Sub
  407. End Class
  408.  
  409. Class EC_ProgressBar
  410.     Inherits Control
  411.     Private m_max As Integer = 100
  412.     Private m_min As Integer = 0
  413.     Private val As Integer = 0
  414.  
  415.     ' Initialize
  416.     Public Sub New()
  417.         MyBase.Size = New Size(150, 15)
  418.         SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.ResizeRedraw Or ControlStyles.DoubleBuffer Or ControlStyles.SupportsTransparentBackColor, True)
  419.         BackColor = Color.FromArgb(25, 0, 0, 0)
  420.         ForeColor = Color.FromArgb(200, 255, 255, 255)
  421.     End Sub
  422.  
  423.     ' Progress Bar Minimum Value
  424.     Public Property Min() As Integer
  425.         Get
  426.             Return m_min
  427.         End Get
  428.         Set(value As Integer)
  429.             If value < 0 Then
  430.                 m_min = 0
  431.             End If
  432.             If value > m_max Then
  433.                 m_min = value
  434.                 m_min = value
  435.             End If
  436.             If value < m_min Then
  437.                 value = m_min
  438.             End If
  439.             Invalidate()
  440.         End Set
  441.     End Property
  442.  
  443.     ' Progress Bar Maximum Value
  444.     Public Property Max() As Integer
  445.         Get
  446.             Return m_max
  447.         End Get
  448.         Set(value As Integer)
  449.             If value < m_min Then
  450.                 m_min = value
  451.             End If
  452.             m_max = value
  453.             If value > m_max Then
  454.                 value = m_max
  455.             End If
  456.             Invalidate()
  457.         End Set
  458.     End Property
  459.  
  460.     ' Progress Bar Current Value
  461.     Public Property Value() As Integer
  462.         Get
  463.             Return val
  464.         End Get
  465.         Set(value As Integer)
  466.             Dim oldValue As Integer = val
  467.             If value < m_min Then
  468.                 val = m_min
  469.             ElseIf value > m_max Then
  470.                 val = m_max
  471.             Else
  472.                 val = value
  473.             End If
  474.  
  475.             Dim percent As Single
  476.  
  477.             Dim newValueRect As New Rectangle(ClientRectangle.X + 2, ClientRectangle.Y + 2, ClientRectangle.Width - 4, ClientRectangle.Height - 4)
  478.             Dim oldValueRect As New Rectangle(ClientRectangle.X + 2, ClientRectangle.Y + 2, ClientRectangle.Width - 4, ClientRectangle.Height - 4)
  479.  
  480.             percent = CSng(val - m_min) / CSng(m_max - m_min)
  481.             newValueRect.Width = CInt(CSng(newValueRect.Width) * percent)
  482.  
  483.             percent = CSng(oldValue - m_min) / CSng(m_max - m_min)
  484.             oldValueRect.Width = CInt(CSng(oldValueRect.Width) * percent)
  485.  
  486.             Dim updateRect As New Rectangle()
  487.  
  488.             If newValueRect.Width > oldValueRect.Width Then
  489.                 updateRect.X = oldValueRect.Size.Width
  490.                 updateRect.Width = newValueRect.Width - oldValueRect.Width
  491.             Else
  492.                 updateRect.X = newValueRect.Size.Width
  493.                 updateRect.Width = oldValueRect.Width - newValueRect.Width
  494.             End If
  495.  
  496.             updateRect.Height = Height
  497.             Invalidate(updateRect)
  498.         End Set
  499.     End Property
  500.  
  501.     Protected Overrides Sub OnPaintBackground(pevent As PaintEventArgs)
  502.         MyBase.OnPaintBackground(pevent)
  503.         Dim g As Graphics = pevent.Graphics
  504.         ' Progress Bar Background Colour
  505.         g.FillRectangle(New SolidBrush(BackColor), New Rectangle(0, 0, Width, Height))
  506.     End Sub
  507.  
  508.     Protected Overrides Sub OnPaint(e As PaintEventArgs)
  509.         MyBase.OnPaint(e)
  510.         Dim g As Graphics = e.Graphics
  511.         Dim brush As New SolidBrush(ForeColor)
  512.         Dim percent As Single = CSng(val - m_min) / CSng(m_max - m_min)
  513.         Dim rect As New Rectangle(2, 2, Width - 4, Height - 4)
  514.         rect.Width = CInt(CSng(rect.Width) * percent)
  515.  
  516.         ' Progress Bar ForeColour
  517.         g.FillRectangle(brush, rect)
  518.     End Sub
  519. End Class
  520.  
  521. Class EC_TextBox
  522.     Inherits RichTextBox
  523.  
  524.     Public Sub New()
  525.         BorderStyle = BorderStyle.None
  526.         Multiline = False
  527.         Size = New Size(Size.Width, 20)
  528.         MaximumSize = New Size(Integer.MaxValue, Size.Height)
  529.         MinimumSize = Size
  530.     End Sub
  531.  
  532.     ' PREVENT FLICKERING
  533.     Protected Overrides Sub OnPaintBackground(pevent As PaintEventArgs)
  534.         MyBase.OnPaintBackground(pevent)
  535.     End Sub
  536.  
  537.     Private Const WM_PAINT As Integer = 15
  538.     Protected Overrides Sub WndProc(ByRef m As Message)
  539.         If m.Msg = WM_PAINT Then
  540.             Invalidate()
  541.             MyBase.WndProc(m)
  542.             Using g As Graphics = Graphics.FromHwnd(Handle)
  543.                 g.InterpolationMode = InterpolationMode.HighQualityBicubic
  544.             End Using
  545.         Else
  546.             MyBase.WndProc(m)
  547.         End If
  548.     End Sub
  549. End Class
Advertisement
Add Comment
Please, Sign In to add comment