Guest User

Untitled

a guest
Jul 29th, 2014
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.83 KB | None | 0 0
  1. #Region " Importations "
  2. Imports System.Drawing.Drawing2D
  3. #End Region
  4.  
  5. Public Class UnknowTheme
  6. #Region " Type de Control "
  7. Inherits ContainerControl
  8. #End Region
  9.  
  10. #Region " Fonction du Control "
  11. Sub New()
  12. Me.Font = New Font("Verdana", 8, FontStyle.Regular, GraphicsUnit.Pixel, Nothing, False)
  13. Me.Dock = DockStyle.Fill
  14. Me.SendToBack()
  15. Me.DoubleBuffered = True
  16. Me.Padding = New Padding(2, 36, 2, 2)
  17. End Sub
  18. #End Region
  19.  
  20. #Region " Propriétés de la Form"
  21. Public Overrides Property Text As String
  22. Get
  23. Return MyBase.Text
  24. End Get
  25. Set(ByVal Value As String)
  26. MyBase.Text = (Value)
  27. Invalidate()
  28. End Set
  29. End Property
  30. Public Overrides Property Font As Font
  31. Get
  32. Return MyBase.Font
  33. End Get
  34. Set(value As Font)
  35. MyBase.Font = (value)
  36. End Set
  37. End Property
  38. #End Region
  39.  
  40. #Region " Initialisation des Variables "
  41. '// Déplacement de la Form
  42. Private Hauteur_Deplacement As Integer = 25
  43. Private Position_Souris As Point = New Point(0, 0)
  44. Private Clique_Souris As Boolean = False
  45. Private Relachement As Boolean = False
  46. '//Agrandissement de la Form
  47. Private Grandit_Form As Boolean = False
  48. '//Resize
  49. Protected Header As Rectangle
  50. Private ParentIsForm As Boolean
  51. Private Flag As IntPtr
  52. Private _Resizable As Boolean = True
  53. Property Resizable() As Boolean
  54. Get
  55. Return _Resizable
  56. End Get
  57. Set(ByVal value As Boolean)
  58. Me._Resizable = value
  59. End Set
  60. End Property
  61. Private _MoveHeight As Integer = 24
  62. Property MoveHeight() As Integer
  63. Get
  64. Return _MoveHeight
  65. End Get
  66. Set(ByVal Value As Integer)
  67. Me._MoveHeight = Value
  68. Me.Header = New Rectangle(7, 7, Me.Width - 14, Me._MoveHeight - 7)
  69. End Set
  70. End Property
  71. '// Ecriture Couleur
  72. Private Ecriture_Couleur As Color = Color.FromArgb(170, 170, 170)
  73. Private Couleur_BordureInt1_Haut As Color = Color.FromArgb(74, 74, 74)
  74. Private Couleur_BordureInt1_Bas As Color = Color.FromArgb(39, 39, 39)
  75. Private Couleur_BordureInt2 As Color = Color.FromArgb(43, 43, 43)
  76. #End Region
  77.  
  78. #Region " Création du design "
  79. Protected Overrides Sub OnPaint(e As PaintEventArgs)
  80. MyBase.OnPaint(e)
  81. '// Ecriture
  82. Dim StringFormat As New StringFormat
  83. StringFormat.LineAlignment = StringAlignment.Center
  84. StringFormat.Alignment = StringAlignment.Near
  85. Dim Rectangle_Ecriture As New Rectangle(15, 0, Me.Width - 15, Me.Hauteur_Deplacement)
  86. e.Graphics.DrawString(Me.Text, Me.Font, New SolidBrush(Me.Ecriture_Couleur), Rectangle_Ecriture, StringFormat)
  87. '// Rectangle haut
  88. Dim Rectangle_BordureInt1 As New Rectangle(1, 1, Width - 3, Hauteur_Deplacement - 4)
  89. Dim Rectangle_BordureInt1_AvecBordure As New Rectangle(0, 0, Width - 1, Hauteur_Deplacement - 2)
  90. Dim Brush_BordureInt1 As New LinearGradientBrush(Rectangle_BordureInt1_AvecBordure, Couleur_BordureInt1_Haut, Couleur_BordureInt1_Bas, LinearGradientMode.Vertical)
  91. e.Graphics.DrawRectangle(New Pen(Brush_BordureInt1, 1), Rectangle_BordureInt1)
  92.  
  93.  
  94. Dim Rectangle_BordureInt2 As New Rectangle(1, Hauteur_Deplacement + 2, Width - 3, Height - Hauteur_Deplacement - 4)
  95. e.Graphics.DrawRectangle(New Pen(Couleur_BordureInt2, 1), Rectangle_BordureInt2)
  96. End Sub
  97. #End Region
  98.  
  99. #Region " Gestion des événements "
  100. Protected Overrides Sub CreateHandle()
  101. MyBase.CreateHandle()
  102. End Sub
  103. Protected Overrides Sub OnHandleCreated(ByVal e As System.EventArgs)
  104. MyBase.OnHandleCreated(e)
  105. Me.FindForm.FormBorderStyle = (FormBorderStyle.None)
  106. End Sub
  107. Protected Overrides Sub OnTextChanged(ByVal e As System.EventArgs)
  108. MyBase.OnTextChanged(e)
  109. Me.Invalidate()
  110. End Sub
  111. Protected Overrides Sub OnResize(ByVal e As System.EventArgs)
  112. MyBase.OnResize(e)
  113. Invalidate()
  114. End Sub
  115. Private Structure Pointer
  116. ReadOnly Cursor As Cursor
  117. ReadOnly Position As Byte
  118. Sub New(ByVal c As Cursor, ByVal p As Byte)
  119. Me.Cursor = c
  120. Me.Position = p
  121. End Sub
  122. End Structure
  123. Private F1 As Boolean
  124. Private PTC As Point
  125. Private F2 As Boolean
  126. Private F3 As Boolean
  127. Private F4 As Boolean
  128. Private Function GetPointer() As Pointer
  129. Me.PTC = Me.PointToClient(Control.MousePosition)
  130. Me.F1 = Me.PTC.X < 7
  131. Me.F2 = Me.PTC.X > Me.Width - 7
  132. Me.F3 = Me.PTC.Y < 7
  133. Me.F4 = Me.PTC.Y > Me.Height - 7
  134. If F1 And F3 Then
  135. Return New Pointer(Cursors.SizeNWSE, 13)
  136. End If
  137. If F1 And F4 Then
  138. Return New Pointer(Cursors.SizeNESW, 16)
  139. End If
  140. If F2 And F3 Then
  141. Return New Pointer(Cursors.SizeNESW, 14)
  142. End If
  143. If F2 And F4 Then
  144. Return New Pointer(Cursors.SizeNWSE, 17)
  145. End If
  146. If F1 Then
  147. Return New Pointer(Cursors.SizeWE, 10)
  148. End If
  149. If F2 Then
  150. Return New Pointer(Cursors.SizeWE, 11)
  151. End If
  152. If F3 Then
  153. Return New Pointer(Cursors.SizeNS, 12)
  154. End If
  155. If F4 Then
  156. Return New Pointer(Cursors.SizeNS, 15)
  157. End If
  158. Return New Pointer(Cursors.Default, 0)
  159. End Function
  160. Private Current As Pointer
  161. Private Pending As Pointer
  162. Private Sub SetCurrent()
  163. Me.Pending = Me.GetPointer()
  164. If Me.Current.Position = Me.Pending.Position Then
  165. Return
  166. End If
  167. Me.Current = Me.GetPointer()
  168. Me.Cursor = Me.Current.Cursor
  169. End Sub
  170. Protected Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
  171. MyBase.OnMouseUp(e)
  172. Me.Clique_Souris = False
  173. Me.Relachement = False
  174. End Sub
  175. Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
  176. MyBase.OnMouseMove(e)
  177. If (Me._Resizable) Then
  178. Me.SetCurrent()
  179. End If
  180. If (Me.Clique_Souris = True And Me.Relachement = False) Then
  181. Me.FindForm.Location = Cursor.Position - Me.Position_Souris
  182. End If
  183. End Sub
  184. Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
  185. MyBase.OnMouseDown(e)
  186. If Not e.Button = MouseButtons.Left Then Return
  187. If Me.ParentIsForm Then If ParentForm.WindowState = FormWindowState.Maximized Then Return
  188.  
  189. If Me.Header.Contains(e.Location) Then
  190. Me.Flag = New IntPtr(2)
  191. ElseIf Me.Current.Position = 0 Or Not Me._Resizable Then
  192. Return
  193. Else
  194. Me.Flag = New IntPtr(Me.Current.Position)
  195. End If
  196. Dim Rectangle_Deplacement As New Rectangle(Nothing, Nothing, Me.Width, Me.Hauteur_Deplacement)
  197. If (e.Button = Windows.Forms.MouseButtons.Left And Rectangle_Deplacement.Contains(e.Location) And e.Clicks = 2) Then
  198. If (Me.FindForm.WindowState = FormWindowState.Normal) Then
  199. Me.Relachement = True
  200. Me.FindForm.WindowState = FormWindowState.Maximized
  201. Else
  202. Me.Relachement = True
  203. Me.FindForm.WindowState = FormWindowState.Normal
  204. End If
  205. End If
  206. Me.Capture = False
  207. Me.DefWndProc(Message.Create(Me.Parent.Handle, 161, Me.Flag, Nothing))
  208. End Sub
  209. Protected Overrides Sub OnSizeChanged(ByVal e As EventArgs)
  210. MyBase.OnSizeChanged(e)
  211. If (Me.Width = 0 OrElse Me.Height = 0) Then
  212. Return
  213. End If
  214. Me.Header = New Rectangle(7, 7, Me.Width - 14, Me._MoveHeight - 7)
  215. Me.Invalidate()
  216. End Sub
  217. #End Region
  218. End Class
Advertisement
Add Comment
Please, Sign In to add comment