• Earn real money by being active: Hello Guest, earn real money by simply being active on the forum — post quality content, get reactions, and help the community. Once you reach the minimum credit amount, you’ll be able to withdraw your balance directly. Learn how it works.

.NET [Theme] Morph Theme [Awesome Clean GUI]

Status
Not open for further replies.

Closter

Leech
User
Joined
Oct 21, 2011
Messages
14
Reputation
0
Reaction score
0
Points
1
Credits
0
‎13 Years of Service‎
94%
Form1.png


Code:
>'Creator: Blessing
'Date: August 22, 2011


Imports System.Drawing.Drawing2D
Imports System.ComponentModel
Imports System.Runtime.InteropServices
MustInherit Class Theme
   Inherits ContainerControl

#Region " Initialization "

   Protected G As Graphics
   Sub New()
       SetStyle(DirectCast(139270, ControlStyles), True)
   End Sub

   Private ParentIsForm As Boolean
   Protected Overrides Sub OnHandleCreated(ByVal e As EventArgs)
       Dock = DockStyle.Fill
       ParentIsForm = TypeOf Parent Is Form
       If ParentIsForm Then
           If Not _TransparencyKey = Color.Empty Then ParentForm.TransparencyKey = _TransparencyKey
           ParentForm.FormBorderStyle = FormBorderStyle.None
       End If
       MyBase.OnHandleCreated(e)
   End Sub

   Overrides Property Text As String
       Get
           Return MyBase.Text
       End Get
       Set(ByVal v As String)
           MyBase.Text = v
           Invalidate()
       End Set
   End Property
#End Region

#Region " Sizing and Movement "

   Private _Resizable As Boolean = True
   Property Resizable() As Boolean
       Get
           Return _Resizable
       End Get
       Set(ByVal value As Boolean)
           _Resizable = value
       End Set
   End Property

   Private _MoveHeight As Integer = 24
   Property MoveHeight() As Integer
       Get
           Return _MoveHeight
       End Get
       Set(ByVal v As Integer)
           _MoveHeight = v
           Header = New Rectangle(7, 7, Width - 14, _MoveHeight - 7)
       End Set
   End Property

   Private Flag As IntPtr
   Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
       If Not e.Button = MouseButtons.Left Then Return
       If ParentIsForm Then If ParentForm.WindowState = FormWindowState.Maximized Then Return

       If Header.Contains(e.Location) Then
           Flag = New IntPtr(2)
       ElseIf Current.Position = 0 Or Not _Resizable Then
           Return
       Else
           Flag = New IntPtr(Current.Position)
       End If

       Capture = False
       DefWndProc(Message.Create(Parent.Handle, 161, Flag, Nothing))

       MyBase.OnMouseDown(e)
   End Sub

   Private Structure Pointer
       ReadOnly Cursor As Cursor, Position As Byte
       Sub New(ByVal c As Cursor, ByVal p As Byte)
           Cursor = c
           Position = p
       End Sub
   End Structure

   Private F1, F2, F3, F4 As Boolean, PTC As Point
   Private Function GetPointer() As Pointer
       PTC = PointToClient(MousePosition)
       F1 = PTC.X < 7
       F2 = PTC.X > Width - 7
       F3 = PTC.Y < 7
       F4 = PTC.Y > Height - 7

       If F1 And F3 Then Return New Pointer(Cursors.SizeNWSE, 13)
       If F1 And F4 Then Return New Pointer(Cursors.SizeNESW, 16)
       If F2 And F3 Then Return New Pointer(Cursors.SizeNESW, 14)
       If F2 And F4 Then Return New Pointer(Cursors.SizeNWSE, 17)
       If F1 Then Return New Pointer(Cursors.SizeWE, 10)
       If F2 Then Return New Pointer(Cursors.SizeWE, 11)
       If F3 Then Return New Pointer(Cursors.SizeNS, 12)
       If F4 Then Return New Pointer(Cursors.SizeNS, 15)
       Return New Pointer(Cursors.Default, 0)
   End Function

   Private Current, Pending As Pointer
   Private Sub SetCurrent()
       Pending = GetPointer()
       If Current.Position = Pending.Position Then Return
       Current = GetPointer()
       Cursor = Current.Cursor
   End Sub

   Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
       If _Resizable Then SetCurrent()
       MyBase.OnMouseMove(e)
   End Sub

   Protected Header As Rectangle
   Protected Overrides Sub OnSizeChanged(ByVal e As EventArgs)
       If Width = 0 OrElse Height = 0 Then Return
       Header = New Rectangle(7, 7, Width - 14, _MoveHeight - 7)
       Invalidate()
       MyBase.OnSizeChanged(e)
   End Sub

#End Region

#Region " Convienence "

   MustOverride Sub PaintHook()
   Protected NotOverridable Overrides Sub OnPaint(ByVal e As PaintEventArgs)
       If Width = 0 OrElse Height = 0 Then Return
       G = e.Graphics
       PaintHook()
   End Sub

   Private _TransparencyKey As Color
   Property TransparencyKey() As Color
       Get
           Return _TransparencyKey
       End Get
       Set(ByVal v As Color)
           _TransparencyKey = v
           Invalidate()
       End Set
   End Property

   Private _Image As Image
   Property Image() As Image
       Get
           Return _Image
       End Get
       Set(ByVal value As Image)
           _Image = value
           Invalidate()
       End Set
   End Property
   ReadOnly Property ImageWidth() As Integer
       Get
           If _Image Is Nothing Then Return 0
           Return _Image.Width
       End Get
   End Property

   Private _Size As Size
   Private _Rectangle As Rectangle
   Private _Gradient As LinearGradientBrush
   Private _Brush As SolidBrush

   Protected Sub DrawCorners(ByVal c As Color, ByVal rect As Rectangle)
       _Brush = New SolidBrush(c)
       G.FillRectangle(_Brush, rect.X, rect.Y, 1, 1)
       G.FillRectangle(_Brush, rect.X + (rect.Width - 1), rect.Y, 1, 1)
       G.FillRectangle(_Brush, rect.X, rect.Y + (rect.Height - 1), 1, 1)
       G.FillRectangle(_Brush, rect.X + (rect.Width - 1), rect.Y + (rect.Height - 1), 1, 1)
   End Sub

   Protected Sub DrawBorders(ByVal p1 As Pen, ByVal p2 As Pen, ByVal rect As Rectangle)
       G.DrawRectangle(p1, rect.X, rect.Y, rect.Width - 1, rect.Height - 1)
       G.DrawRectangle(p2, rect.X + 1, rect.Y + 1, rect.Width - 3, rect.Height - 3)
   End Sub

   Protected Sub DrawText(ByVal a As HorizontalAlignment, ByVal c As Color, ByVal x As Integer)
       DrawText(a, c, x, 0)
   End Sub
   Protected Sub DrawText(ByVal a As HorizontalAlignment, ByVal c As Color, ByVal x As Integer, ByVal y As Integer)
       If String.IsNullOrEmpty(Text) Then Return
       _Size = G.MeasureString(Text, Font).ToSize
       _Brush = New SolidBrush(c)

       Select Case a
           Case HorizontalAlignment.Left
               G.DrawString(Text, Font, _Brush, x, _MoveHeight \ 2 - _Size.Height \ 2 + y)
           Case HorizontalAlignment.Right
               G.DrawString(Text, Font, _Brush, Width - _Size.Width - x, _MoveHeight \ 2 - _Size.Height \ 2 + y)
           Case HorizontalAlignment.Center
               G.DrawString(Text, Font, _Brush, Width \ 2 - _Size.Width \ 2 + x, _MoveHeight \ 2 - _Size.Height \ 2 + y)
       End Select
   End Sub

   Protected Sub DrawIcon(ByVal a As HorizontalAlignment, ByVal x As Integer)
       DrawIcon(a, x, 0)
   End Sub
   Protected Sub DrawIcon(ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
       If _Image Is Nothing Then Return
       Select Case a
           Case HorizontalAlignment.Left
               G.DrawImage(_Image, x, _MoveHeight \ 2 - _Image.Height \ 2 + y)
           Case HorizontalAlignment.Right
               G.DrawImage(_Image, Width - _Image.Width - x, _MoveHeight \ 2 - _Image.Height \ 2 + y)
           Case HorizontalAlignment.Center
               G.DrawImage(_Image, Width \ 2 - _Image.Width \ 2, _MoveHeight \ 2 - _Image.Height \ 2)
       End Select
   End Sub

   Protected Sub DrawGradient(ByVal c1 As Color, ByVal c2 As Color, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal angle As Single)
       _Rectangle = New Rectangle(x, y, width, height)
       _Gradient = New LinearGradientBrush(_Rectangle, c1, c2, angle)
       G.FillRectangle(_Gradient, _Rectangle)
   End Sub

#End Region

End Class
MustInherit Class ThemeControl
   Inherits Control

#Region " Initialization "

   Protected G As Graphics, B As Bitmap
   Sub New()
       SetStyle(DirectCast(139270, ControlStyles), True)
       B = New Bitmap(1, 1)
       G = Graphics.FromImage(B)
   End Sub

   Sub AllowTransparent()
       SetStyle(ControlStyles.Opaque, False)
       SetStyle(ControlStyles.SupportsTransparentBackColor, True)
   End Sub

   Overrides Property Text As String
       Get
           Return MyBase.Text
       End Get
       Set(ByVal v As String)
           MyBase.Text = v
           Invalidate()
       End Set
   End Property
#End Region

#Region " Mouse Handling "

   Protected Enum State As Byte
       MouseNone = 0
       MouseOver = 1
       MouseDown = 2
   End Enum

   Protected MouseState As State
   Protected Overrides Sub OnMouseLeave(ByVal e As EventArgs)
       ChangeMouseState(State.MouseNone)
       MyBase.OnMouseLeave(e)
   End Sub
   Protected Overrides Sub OnMouseEnter(ByVal e As EventArgs)
       ChangeMouseState(State.MouseOver)
       MyBase.OnMouseEnter(e)
   End Sub
   Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
       ChangeMouseState(State.MouseOver)
       MyBase.OnMouseUp(e)
   End Sub
   Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
       If e.Button = MouseButtons.Left Then ChangeMouseState(State.MouseDown)
       MyBase.OnMouseDown(e)
   End Sub

   Private Sub ChangeMouseState(ByVal e As State)
       MouseState = e
       Invalidate()
   End Sub

#End Region

#Region " Convienence "

   MustOverride Sub PaintHook()
   Protected NotOverridable Overrides Sub OnPaint(ByVal e As PaintEventArgs)
       If Width = 0 OrElse Height = 0 Then Return
       PaintHook()
       e.Graphics.DrawImage(B, 0, 0)
   End Sub

   Protected Overrides Sub OnSizeChanged(ByVal e As EventArgs)
       If Not Width = 0 AndAlso Not Height = 0 Then
           B = New Bitmap(Width, Height)
           G = Graphics.FromImage(B)
           Invalidate()
       End If
       MyBase.OnSizeChanged(e)
   End Sub

   Private _NoRounding As Boolean
   Property NoRounding() As Boolean
       Get
           Return _NoRounding
       End Get
       Set(ByVal v As Boolean)
           _NoRounding = v
           Invalidate()
       End Set
   End Property

   Private _Image As Image
   Property Image() As Image
       Get
           Return _Image
       End Get
       Set(ByVal value As Image)
           _Image = value
           Invalidate()
       End Set
   End Property
   ReadOnly Property ImageWidth() As Integer
       Get
           If _Image Is Nothing Then Return 0
           Return _Image.Width
       End Get
   End Property
   ReadOnly Property ImageTop() As Integer
       Get
           If _Image Is Nothing Then Return 0
           Return Height \ 2 - _Image.Height \ 2
       End Get
   End Property

   Private _Size As Size
   Private _Rectangle As Rectangle
   Private _Gradient As LinearGradientBrush
   Private _Brush As SolidBrush

   Protected Sub DrawCorners(ByVal c As Color, ByVal rect As Rectangle)
       If _NoRounding Then Return

       B.SetPixel(rect.X, rect.Y, c)
       B.SetPixel(rect.X + (rect.Width - 1), rect.Y, c)
       B.SetPixel(rect.X, rect.Y + (rect.Height - 1), c)
       B.SetPixel(rect.X + (rect.Width - 1), rect.Y + (rect.Height - 1), c)
   End Sub

   Protected Sub DrawBorders(ByVal p1 As Pen, ByVal p2 As Pen, ByVal rect As Rectangle)
       G.DrawRectangle(p1, rect.X, rect.Y, rect.Width - 1, rect.Height - 1)
       G.DrawRectangle(p2, rect.X + 1, rect.Y + 1, rect.Width - 3, rect.Height - 3)
   End Sub

   Protected Sub DrawText(ByVal a As HorizontalAlignment, ByVal c As Color, ByVal x As Integer)
       DrawText(a, c, x, 0)
   End Sub
   Protected Sub DrawText(ByVal a As HorizontalAlignment, ByVal c As Color, ByVal x As Integer, ByVal y As Integer)
       If String.IsNullOrEmpty(Text) Then Return
       _Size = G.MeasureString(Text, Font).ToSize
       _Brush = New SolidBrush(c)

       Select Case a
           Case HorizontalAlignment.Left
               G.DrawString(Text, Font, _Brush, x, Height \ 2 - _Size.Height \ 2 + y)
           Case HorizontalAlignment.Right
               G.DrawString(Text, Font, _Brush, Width - _Size.Width - x, Height \ 2 - _Size.Height \ 2 + y)
           Case HorizontalAlignment.Center
               G.DrawString(Text, Font, _Brush, Width \ 2 - _Size.Width \ 2 + x, Height \ 2 - _Size.Height \ 2 + y)
       End Select
   End Sub

   Protected Sub DrawIcon(ByVal a As HorizontalAlignment, ByVal x As Integer)
       DrawIcon(a, x, 0)
   End Sub
   Protected Sub DrawIcon(ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
       If _Image Is Nothing Then Return
       Select Case a
           Case HorizontalAlignment.Left
               G.DrawImage(_Image, x, Height \ 2 - _Image.Height \ 2 + y)
           Case HorizontalAlignment.Right
               G.DrawImage(_Image, Width - _Image.Width - x, Height \ 2 - _Image.Height \ 2 + y)
           Case HorizontalAlignment.Center
               G.DrawImage(_Image, Width \ 2 - _Image.Width \ 2, Height \ 2 - _Image.Height \ 2)
       End Select
   End Sub

   Protected Sub DrawGradient(ByVal c1 As Color, ByVal c2 As Color, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal angle As Single)
       _Rectangle = New Rectangle(x, y, width, height)
       _Gradient = New LinearGradientBrush(_Rectangle, c1, c2, angle)
       G.FillRectangle(_Gradient, _Rectangle)
   End Sub
#End Region

End Class
MustInherit Class ThemeContainerControl
   Inherits ContainerControl

#Region " Initialization "

   Protected G As Graphics, B As Bitmap
   Sub New()
       SetStyle(DirectCast(139270, ControlStyles), True)
       B = New Bitmap(1, 1)
       G = Graphics.FromImage(B)
   End Sub

   Sub AllowTransparent()
       SetStyle(ControlStyles.Opaque, False)
       SetStyle(ControlStyles.SupportsTransparentBackColor, True)
   End Sub

#End Region

#Region " Convienence "

   MustOverride Sub PaintHook()
   Protected NotOverridable Overrides Sub OnPaint(ByVal e As PaintEventArgs)
       If Width = 0 OrElse Height = 0 Then Return
       PaintHook()
       e.Graphics.DrawImage(B, 0, 0)
   End Sub

   Protected Overrides Sub OnSizeChanged(ByVal e As EventArgs)
       If Not Width = 0 AndAlso Not Height = 0 Then
           B = New Bitmap(Width, Height)
           G = Graphics.FromImage(B)
           Invalidate()
       End If
       MyBase.OnSizeChanged(e)
   End Sub

   Private _NoRounding As Boolean
   Property NoRounding() As Boolean
       Get
           Return _NoRounding
       End Get
       Set(ByVal v As Boolean)
           _NoRounding = v
           Invalidate()
       End Set
   End Property

   Private _Rectangle As Rectangle
   Private _Gradient As LinearGradientBrush

   Protected Sub DrawCorners(ByVal c As Color, ByVal rect As Rectangle)
       If _NoRounding Then Return
       B.SetPixel(rect.X, rect.Y, c)
       B.SetPixel(rect.X + (rect.Width - 1), rect.Y, c)
       B.SetPixel(rect.X, rect.Y + (rect.Height - 1), c)
       B.SetPixel(rect.X + (rect.Width - 1), rect.Y + (rect.Height - 1), c)
   End Sub

   Protected Sub DrawBorders(ByVal p1 As Pen, ByVal p2 As Pen, ByVal rect As Rectangle)
       G.DrawRectangle(p1, rect.X, rect.Y, rect.Width - 1, rect.Height - 1)
       G.DrawRectangle(p2, rect.X + 1, rect.Y + 1, rect.Width - 3, rect.Height - 3)
   End Sub

   Protected Sub DrawGradient(ByVal c1 As Color, ByVal c2 As Color, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal angle As Single)
       _Rectangle = New Rectangle(x, y, width, height)
       _Gradient = New LinearGradientBrush(_Rectangle, c1, c2, angle)
       G.FillRectangle(_Gradient, _Rectangle)
   End Sub
#End Region

End Class

Class MTheme
   Inherits Theme
   Sub New()
       Resizable = False
       Font = New Font("Tahoma", 8.25!)
       ForeColor = Color.Blue
       BackColor = Color.White
       TransparencyKey = Color.Fuchsia
       MoveHeight = 20
   End Sub
   Overrides Sub PaintHook()
       G.Clear(BackColor)
       DrawGradient(Color.Green, Color.GreenYellow, 0, 0, Width, 20, 90S)
       DrawGradient(Color.LightGray, Color.Silver, 0, 20, Width, Height - 25, 90S)
       DrawGradient(Color.Green, Color.GreenYellow, 0, Height - 25, Width, Height + 25 - Height, 90S)
       DrawGradient(Color.Green, Color.GreenYellow, 0, Height + 25 - Height - 5, 10, Height - 45, 180S)
       DrawGradient(Color.Green, Color.GreenYellow, Width - 10, Height + 25 - Height - 5, 10, Height - 45, 180S)
       DrawCorners(Color.Fuchsia, ClientRectangle)
       DrawText(HorizontalAlignment.Center, ForeColor, ImageWidth)
       DrawBorders(Pens.DodgerBlue, Pens.White, ClientRectangle)
   End Sub
End Class
Class MButton
   Inherits ThemeControl

   Public Overrides Sub PaintHook()
       If MouseState = State.MouseDown Then
           DrawGradient(Color.Green, Color.GreenYellow, 0, 0, Width, Height, 90S)
       ElseIf MouseState = State.MouseOver Then
           DrawGradient(Color.GreenYellow, Color.Green, 0, 0, Width, Height, 90S)
       Else
           DrawGradient(Color.LightGreen, Color.Green, 0, 0, Width, Height, 90S)
       End If
       DrawText(HorizontalAlignment.Center, ForeColor, 0)
       DrawBorders(Pens.Blue, Pens.White, ClientRectangle)
   End Sub
End Class

Class MProgressBar
   Inherits ThemeControl

   Private _Maximum As Integer = 100
   Public Property Maximum() As Integer
       Get
           Return _Maximum
       End Get
       Set(ByVal value As Integer)
           If value < 1 Then value = 1
           If value < _Value Then _Value = value
           _Maximum = value
           Invalidate()
       End Set
   End Property

   Private _Value As Integer = 50
   Public Property Value() As Integer
       Get
           Return _Value
       End Get
       Set(ByVal value As Integer)
           If value > _Maximum Then value = _Maximum
           If value < 1 Then value = 1
           _Value = value
           Invalidate()
       End Set
   End Property

   Overrides Sub PaintHook()
       G.Clear(Color.GreenYellow)
       If (_Value > 0) Then
           DrawGradient(Color.Green, Color.GreenYellow, 0, 0, CInt((_Value / _Maximum) * Width), Height, 90S)
       End If
       G.DrawRectangle(Pens.White, 0, 0, Width - 1, Height - 1)
       DrawBorders(Pens.Blue, Pens.White, ClientRectangle)
   End Sub
End Class
Instructions On How To Use Them:

1. Make a New Project

2. Add a Class

3. Delete everything there is in the Class and replace it with the Morph Theme source

4. Debug your project

5. All the way on top of your Toolbar should be these:

capture.png


6. Just drag and drop them into the Form and enjoy!
 
Status
Not open for further replies.
Back
Top