Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Region " Importations "
- Imports System.Drawing.Drawing2D
- #End Region
- Public Class UnknowTheme
- #Region " Type de Control "
- Inherits ContainerControl
- #End Region
- #Region " Fonction du Control "
- Sub New()
- Me.Font = New Font("Verdana", 8, FontStyle.Regular, GraphicsUnit.Pixel, Nothing, False)
- Me.Dock = DockStyle.Fill
- Me.SendToBack()
- Me.DoubleBuffered = True
- Me.Padding = New Padding(2, 36, 2, 2)
- End Sub
- #End Region
- #Region " Propriétés de la Form"
- Public Overrides Property Text As String
- Get
- Return MyBase.Text
- End Get
- Set(ByVal Value As String)
- MyBase.Text = (Value)
- Invalidate()
- End Set
- End Property
- Public Overrides Property Font As Font
- Get
- Return MyBase.Font
- End Get
- Set(value As Font)
- MyBase.Font = (value)
- End Set
- End Property
- #End Region
- #Region " Initialisation des Variables "
- '// Déplacement de la Form
- Private Hauteur_Deplacement As Integer = 25
- Private Position_Souris As Point = New Point(0, 0)
- Private Clique_Souris As Boolean = False
- Private Relachement As Boolean = False
- '//Agrandissement de la Form
- Private Grandit_Form As Boolean = False
- '//Resize
- Protected Header As Rectangle
- Private ParentIsForm As Boolean
- Private Flag As IntPtr
- Private _Resizable As Boolean = True
- Property Resizable() As Boolean
- Get
- Return _Resizable
- End Get
- Set(ByVal value As Boolean)
- Me._Resizable = value
- End Set
- End Property
- Private _MoveHeight As Integer = 24
- Property MoveHeight() As Integer
- Get
- Return _MoveHeight
- End Get
- Set(ByVal Value As Integer)
- Me._MoveHeight = Value
- Me.Header = New Rectangle(7, 7, Me.Width - 14, Me._MoveHeight - 7)
- End Set
- End Property
- '// Ecriture Couleur
- Private Ecriture_Couleur As Color = Color.FromArgb(170, 170, 170)
- Private Couleur_BordureInt1_Haut As Color = Color.FromArgb(74, 74, 74)
- Private Couleur_BordureInt1_Bas As Color = Color.FromArgb(39, 39, 39)
- Private Couleur_BordureInt2 As Color = Color.FromArgb(43, 43, 43)
- #End Region
- #Region " Création du design "
- Protected Overrides Sub OnPaint(e As PaintEventArgs)
- MyBase.OnPaint(e)
- '// Ecriture
- Dim StringFormat As New StringFormat
- StringFormat.LineAlignment = StringAlignment.Center
- StringFormat.Alignment = StringAlignment.Near
- Dim Rectangle_Ecriture As New Rectangle(15, 0, Me.Width - 15, Me.Hauteur_Deplacement)
- e.Graphics.DrawString(Me.Text, Me.Font, New SolidBrush(Me.Ecriture_Couleur), Rectangle_Ecriture, StringFormat)
- '// Rectangle haut
- Dim Rectangle_BordureInt1 As New Rectangle(1, 1, Width - 3, Hauteur_Deplacement - 4)
- Dim Rectangle_BordureInt1_AvecBordure As New Rectangle(0, 0, Width - 1, Hauteur_Deplacement - 2)
- Dim Brush_BordureInt1 As New LinearGradientBrush(Rectangle_BordureInt1_AvecBordure, Couleur_BordureInt1_Haut, Couleur_BordureInt1_Bas, LinearGradientMode.Vertical)
- e.Graphics.DrawRectangle(New Pen(Brush_BordureInt1, 1), Rectangle_BordureInt1)
- Dim Rectangle_BordureInt2 As New Rectangle(1, Hauteur_Deplacement + 2, Width - 3, Height - Hauteur_Deplacement - 4)
- e.Graphics.DrawRectangle(New Pen(Couleur_BordureInt2, 1), Rectangle_BordureInt2)
- End Sub
- #End Region
- #Region " Gestion des événements "
- Protected Overrides Sub CreateHandle()
- MyBase.CreateHandle()
- End Sub
- Protected Overrides Sub OnHandleCreated(ByVal e As System.EventArgs)
- MyBase.OnHandleCreated(e)
- Me.FindForm.FormBorderStyle = (FormBorderStyle.None)
- End Sub
- Protected Overrides Sub OnTextChanged(ByVal e As System.EventArgs)
- MyBase.OnTextChanged(e)
- Me.Invalidate()
- End Sub
- Protected Overrides Sub OnResize(ByVal e As System.EventArgs)
- MyBase.OnResize(e)
- Invalidate()
- End Sub
- Private Structure Pointer
- ReadOnly Cursor As Cursor
- ReadOnly Position As Byte
- Sub New(ByVal c As Cursor, ByVal p As Byte)
- Me.Cursor = c
- Me.Position = p
- End Sub
- End Structure
- Private F1 As Boolean
- Private PTC As Point
- Private F2 As Boolean
- Private F3 As Boolean
- Private F4 As Boolean
- Private Function GetPointer() As Pointer
- Me.PTC = Me.PointToClient(Control.MousePosition)
- Me.F1 = Me.PTC.X < 7
- Me.F2 = Me.PTC.X > Me.Width - 7
- Me.F3 = Me.PTC.Y < 7
- Me.F4 = Me.PTC.Y > Me.Height - 7
- If F1 And F3 Then
- Return New Pointer(Cursors.SizeNWSE, 13)
- End If
- If F1 And F4 Then
- Return New Pointer(Cursors.SizeNESW, 16)
- End If
- If F2 And F3 Then
- Return New Pointer(Cursors.SizeNESW, 14)
- End If
- If F2 And F4 Then
- Return New Pointer(Cursors.SizeNWSE, 17)
- End If
- If F1 Then
- Return New Pointer(Cursors.SizeWE, 10)
- End If
- If F2 Then
- Return New Pointer(Cursors.SizeWE, 11)
- End If
- If F3 Then
- Return New Pointer(Cursors.SizeNS, 12)
- End If
- If F4 Then
- Return New Pointer(Cursors.SizeNS, 15)
- End If
- Return New Pointer(Cursors.Default, 0)
- End Function
- Private Current As Pointer
- Private Pending As Pointer
- Private Sub SetCurrent()
- Me.Pending = Me.GetPointer()
- If Me.Current.Position = Me.Pending.Position Then
- Return
- End If
- Me.Current = Me.GetPointer()
- Me.Cursor = Me.Current.Cursor
- End Sub
- Protected Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
- MyBase.OnMouseUp(e)
- Me.Clique_Souris = False
- Me.Relachement = False
- End Sub
- Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
- MyBase.OnMouseMove(e)
- If (Me._Resizable) Then
- Me.SetCurrent()
- End If
- If (Me.Clique_Souris = True And Me.Relachement = False) Then
- Me.FindForm.Location = Cursor.Position - Me.Position_Souris
- End If
- End Sub
- Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
- MyBase.OnMouseDown(e)
- If Not e.Button = MouseButtons.Left Then Return
- If Me.ParentIsForm Then If ParentForm.WindowState = FormWindowState.Maximized Then Return
- If Me.Header.Contains(e.Location) Then
- Me.Flag = New IntPtr(2)
- ElseIf Me.Current.Position = 0 Or Not Me._Resizable Then
- Return
- Else
- Me.Flag = New IntPtr(Me.Current.Position)
- End If
- Dim Rectangle_Deplacement As New Rectangle(Nothing, Nothing, Me.Width, Me.Hauteur_Deplacement)
- If (e.Button = Windows.Forms.MouseButtons.Left And Rectangle_Deplacement.Contains(e.Location) And e.Clicks = 2) Then
- If (Me.FindForm.WindowState = FormWindowState.Normal) Then
- Me.Relachement = True
- Me.FindForm.WindowState = FormWindowState.Maximized
- Else
- Me.Relachement = True
- Me.FindForm.WindowState = FormWindowState.Normal
- End If
- End If
- Me.Capture = False
- Me.DefWndProc(Message.Create(Me.Parent.Handle, 161, Me.Flag, Nothing))
- End Sub
- Protected Overrides Sub OnSizeChanged(ByVal e As EventArgs)
- MyBase.OnSizeChanged(e)
- If (Me.Width = 0 OrElse Me.Height = 0) Then
- Return
- End If
- Me.Header = New Rectangle(7, 7, Me.Width - 14, Me._MoveHeight - 7)
- Me.Invalidate()
- End Sub
- #End Region
- End Class
Advertisement
Add Comment
Please, Sign In to add comment