Advertisement
benito

Thème [Vb net]

Sep 7th, 2011
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.54 KB | None | 0 0
  1. Imports System.Drawing.Drawing2D
  2. Public Class Draw
  3. Shared Sub Gradient(ByVal g As Graphics, ByVal c1 As Color, ByVal c2 As Color, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  4. Dim R As New Rectangle(x, y, width, height)
  5. Using T As New LinearGradientBrush(R, c1, c2, LinearGradientMode.Vertical)
  6. g.FillRectangle(T, R)
  7. End Using
  8. End Sub
  9. Shared Sub Blend(ByVal g As Graphics, ByVal c1 As Color, ByVal c2 As Color, ByVal c3 As Color, ByVal c As Single, ByVal d As Integer, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  10. Dim V As New ColorBlend(3)
  11. V.Colors = New Color() {c1, c2, c3}
  12. V.Positions = New Single() {0, c, 1}
  13. Dim R As New Rectangle(x, y, width, height)
  14. Using T As New LinearGradientBrush(R, c1, c1, CType(d, LinearGradientMode))
  15. T.InterpolationColors = V : g.FillRectangle(T, R)
  16. End Using
  17. End Sub
  18. End Class
  19. 'Pearl Theme
  20. Public Class PTheme : Inherits Control
  21. Private _TitleHeight As Integer = 25
  22. Public Property TitleHeight() As Integer
  23. Get
  24. Return _TitleHeight
  25. End Get
  26. Set(ByVal v As Integer)
  27. If v > Height Then v = Height
  28. If v < 2 Then Height = 1
  29. _TitleHeight = v : Invalidate()
  30. End Set
  31. End Property
  32. Private _TitleAlign As HorizontalAlignment
  33. Public Property TitleAlign() As HorizontalAlignment
  34. Get
  35. Return _TitleAlign
  36. End Get
  37. Set(ByVal v As HorizontalAlignment)
  38. _TitleAlign = v : Invalidate()
  39. End Set
  40. End Property
  41. Protected Overrides Sub OnHandleCreated(ByVal e As System.EventArgs)
  42. Dock = 5
  43. If TypeOf Parent Is Form Then CType(Parent, Form).FormBorderStyle = 0
  44. MyBase.OnHandleCreated(e)
  45. End Sub
  46. Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
  47. If New Rectangle(Parent.Location.X, Parent.Location.Y, Width - 1, _TitleHeight - 1).IntersectsWith(New Rectangle(MousePosition.X, MousePosition.Y, 1, 1)) Then
  48. Capture = False : Dim M = Message.Create(Parent.Handle, 161, 2, 0) : DefWndProc(M)
  49. End If : MyBase.OnMouseDown(e)
  50. End Sub
  51. Dim C1 As Color = Color.FromArgb(240, 240, 240), C2 As Color = Color.FromArgb(230, 230, 230), C3 As Color = Color.FromArgb(190, 190, 190)
  52. Protected Overrides Sub OnPaintBackground(ByVal pevent As System.Windows.Forms.PaintEventArgs)
  53. End Sub
  54. Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  55. Using B As New Bitmap(Width, Height)
  56. Using G = Graphics.FromImage(B)
  57. G.Clear(Color.FromArgb(245, 245, 245))
  58.  
  59. Draw.Blend(G, Color.White, C2, C1, 0.7, 1, 0, 0, Width, _TitleHeight)
  60.  
  61. G.FillRectangle(New SolidBrush(Color.FromArgb(80, 255, 255, 255)), 0, 0, Width, CInt(_TitleHeight / 2))
  62. G.DrawRectangle(New Pen(Color.FromArgb(100, 255, 255, 255)), 1, 1, Width - 3, _TitleHeight - 2)
  63.  
  64. Dim S = G.MeasureString(Text, Font), O = 6
  65. If _TitleAlign = 2 Then O = Width / 2 - S.Width / 2
  66. If _TitleAlign = 1 Then O = Width - S.Width - 6
  67. G.DrawString(Text, Font, New SolidBrush(C3), O, CInt(_TitleHeight / 2 - S.Height / 2))
  68.  
  69. G.DrawLine(New Pen(C3), 0, _TitleHeight, Width, _TitleHeight)
  70. G.DrawLine(Pens.White, 0, _TitleHeight + 1, Width, _TitleHeight + 1)
  71. G.DrawRectangle(New Pen(C3), 0, 0, Width - 1, Height - 1)
  72.  
  73. e.Graphics.DrawImage(B.Clone, 0, 0)
  74. End Using
  75. End Using
  76. End Sub
  77. End Class
  78. Public Class PButton : Inherits Control
  79. Sub New()
  80. ForeColor = C3
  81. End Sub
  82. Private State As Integer
  83. Protected Overrides Sub OnMouseEnter(ByVal e As System.EventArgs)
  84. State = 1 : Invalidate() : MyBase.OnMouseEnter(e)
  85. End Sub
  86. Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
  87. State = 2 : Invalidate() : MyBase.OnMouseDown(e)
  88. End Sub
  89. Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)
  90. State = 0 : Invalidate() : MyBase.OnMouseLeave(e)
  91. End Sub
  92. Protected Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
  93. State = 1 : Invalidate() : MyBase.OnMouseUp(e)
  94. End Sub
  95. Dim C1 As Color = Color.FromArgb(240, 240, 240), C2 As Color = Color.FromArgb(230, 230, 230), C3 As Color = Color.FromArgb(190, 190, 190)
  96. Protected Overrides Sub OnPaintBackground(ByVal pevent As System.Windows.Forms.PaintEventArgs)
  97. End Sub
  98. Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  99. Using B As New Bitmap(Width, Height)
  100. Using G = Graphics.FromImage(B)
  101. If State = 2 Then
  102. Draw.Gradient(G, C2, Color.WhiteSmoke, 1, 1, Width, Height)
  103. Else
  104. Draw.Gradient(G, Color.WhiteSmoke, C2, 1, 1, Width, Height)
  105. End If
  106.  
  107. If State < 2 Then G.FillRectangle(New SolidBrush(Color.FromArgb(80, 255, 255, 255)), 0, 0, Width, CInt(Height * 0.3))
  108.  
  109. Dim S = G.MeasureString(Text, Font)
  110. G.DrawString(Text, Font, New SolidBrush(ForeColor), Width / 2 - S.Width / 2, Height / 2 - S.Height / 2)
  111. G.DrawRectangle(New Pen(C3), 0, 0, Width - 1, Height - 1)
  112.  
  113. e.Graphics.DrawImage(B.Clone, 0, 0)
  114. End Using
  115. End Using
  116. End Sub
  117. End Class
  118. Public Class PProgress : Inherits Control
  119. Private _Value As Integer
  120. Public Property Value() As Integer
  121. Get
  122. Return _Value
  123. End Get
  124. Set(ByVal value As Integer)
  125. _Value = value : Invalidate()
  126. End Set
  127. End Property
  128. Private _Maximum As Integer = 100
  129. Public Property Maximum() As Integer
  130. Get
  131. Return _Maximum
  132. End Get
  133. Set(ByVal value As Integer)
  134. If value = 0 Then value = 1
  135. _Maximum = value : Invalidate()
  136. End Set
  137. End Property
  138. Dim C1 As Color = Color.FromArgb(240, 240, 240), C2 As Color = Color.FromArgb(230, 230, 230), C3 As Color = Color.FromArgb(190, 190, 190)
  139. Protected Overrides Sub OnPaintBackground(ByVal pevent As System.Windows.Forms.PaintEventArgs)
  140. End Sub
  141. Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  142. Dim V As Integer = Width * _Value / _Maximum
  143. Using B As New Bitmap(Width, Height)
  144. Using G = Graphics.FromImage(B)
  145. Draw.Gradient(G, C2, C1, 1, 1, Width - 2, Height - 2)
  146. G.DrawRectangle(New Pen(C2), 1, 1, V - 3, Height - 3)
  147. Draw.Gradient(G, C1, C2, 2, 2, V - 4, Height - 4)
  148.  
  149. G.FillRectangle(New SolidBrush(Color.FromArgb(50, 255, 255, 255)), 2, 2, V - 4, CInt(Height / 2) - 2)
  150. G.DrawRectangle(New Pen(C3), 0, 0, Width - 1, Height - 1)
  151.  
  152. e.Graphics.DrawImage(B.Clone, 0, 0)
  153. End Using
  154. End Using
  155. End Sub
  156. End Class
  157. 'Modern Theme
  158. Public Class MTheme : Inherits Control
  159. Private _TitleHeight As Integer = 25
  160. Public Property TitleHeight() As Integer
  161. Get
  162. Return _TitleHeight
  163. End Get
  164. Set(ByVal v As Integer)
  165. If v > Height Then v = Height
  166. If v < 2 Then Height = 1
  167. _TitleHeight = v : Invalidate()
  168. End Set
  169. End Property
  170. Private _TitleAlign As HorizontalAlignment = 2
  171. Public Property TitleAlign() As HorizontalAlignment
  172. Get
  173. Return _TitleAlign
  174. End Get
  175. Set(ByVal v As HorizontalAlignment)
  176. _TitleAlign = v : Invalidate()
  177. End Set
  178. End Property
  179. Protected Overrides Sub OnHandleCreated(ByVal e As System.EventArgs)
  180. Dock = 5
  181. If TypeOf Parent Is Form Then CType(Parent, Form).FormBorderStyle = 0
  182. MyBase.OnHandleCreated(e)
  183. End Sub
  184. Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
  185. If New Rectangle(Parent.Location.X, Parent.Location.Y, Width - 1, _TitleHeight - 1).IntersectsWith(New Rectangle(MousePosition.X, MousePosition.Y, 1, 1)) Then
  186. Capture = False : Dim M = Message.Create(Parent.Handle, 161, 2, 0) : DefWndProc(M)
  187. End If : MyBase.OnMouseDown(e)
  188. End Sub
  189. Dim C1 As Color = Color.FromArgb(74, 74, 74), C2 As Color = Color.FromArgb(63, 63, 63), C3 As Color = Color.FromArgb(41, 41, 41), _
  190. C4 As Color = Color.FromArgb(27, 27, 27), C5 As Color = Color.FromArgb(0, 0, 0, 0), C6 As Color = Color.FromArgb(25, 255, 255, 255)
  191. Protected Overrides Sub OnPaintBackground(ByVal pevent As System.Windows.Forms.PaintEventArgs)
  192. End Sub
  193. Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  194. Using B As New Bitmap(Width, Height)
  195. Using G = Graphics.FromImage(B)
  196. G.Clear(C3)
  197.  
  198. Draw.Gradient(G, C4, C3, 0, 0, Width, _TitleHeight)
  199.  
  200. Dim S = G.MeasureString(Text, Font), O = 6
  201. If _TitleAlign = 2 Then O = Width / 2 - S.Width / 2
  202. If _TitleAlign = 1 Then O = Width - S.Width - 6
  203. Dim R As New Rectangle(O, (_TitleHeight + 2) / 2 - S.Height / 2, S.Width, S.Height)
  204. Using T As New LinearGradientBrush(R, C1, C3, LinearGradientMode.Vertical)
  205. G.DrawString(Text, Font, T, R)
  206. End Using
  207.  
  208. G.DrawLine(New Pen(C3), 0, 1, Width, 1)
  209.  
  210. Draw.Blend(G, C5, C6, C5, 0.5, 0, 0, _TitleHeight + 1, Width, 1)
  211.  
  212. G.DrawLine(New Pen(C4), 0, _TitleHeight, Width, _TitleHeight)
  213. G.DrawRectangle(New Pen(C4), 0, 0, Width - 1, Height - 1)
  214.  
  215. e.Graphics.DrawImage(B.Clone, 0, 0)
  216. End Using
  217. End Using
  218. End Sub
  219. End Class
  220. Public Class MButton : Inherits Control
  221. Sub New()
  222. ForeColor = Color.FromArgb(65, 65, 65)
  223. End Sub
  224. Private State As Integer
  225. Protected Overrides Sub OnMouseEnter(ByVal e As System.EventArgs)
  226. State = 1 : Invalidate() : MyBase.OnMouseEnter(e)
  227. End Sub
  228. Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
  229. State = 2 : Invalidate() : MyBase.OnMouseDown(e)
  230. End Sub
  231. Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)
  232. State = 0 : Invalidate() : MyBase.OnMouseLeave(e)
  233. End Sub
  234. Protected Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
  235. State = 1 : Invalidate() : MyBase.OnMouseUp(e)
  236. End Sub
  237. Dim C1 As Color = Color.FromArgb(31, 31, 31), C2 As Color = Color.FromArgb(41, 41, 41), C3 As Color = Color.FromArgb(51, 51, 51), _
  238. C4 As Color = Color.FromArgb(0, 0, 0, 0), C5 As Color = Color.FromArgb(25, 255, 255, 255)
  239. Protected Overrides Sub OnPaintBackground(ByVal pevent As System.Windows.Forms.PaintEventArgs)
  240. End Sub
  241. Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  242. Using B As New Bitmap(Width, Height)
  243. Using G = Graphics.FromImage(B)
  244. G.DrawRectangle(New Pen(C1), 0, 0, Width - 1, Height - 1)
  245.  
  246. If State = 2 Then
  247. Draw.Gradient(G, C2, C3, 1, 1, Width - 2, Height - 2)
  248. Else
  249. Draw.Gradient(G, C3, C2, 1, 1, Width - 2, Height - 2)
  250. End If
  251.  
  252. Dim O = G.MeasureString(Text, Font)
  253. G.DrawString(Text, Font, New SolidBrush(ForeColor), Width / 2 - O.Width / 2, Height / 2 - O.Height / 2)
  254.  
  255. Draw.Blend(G, C4, C5, C4, 0.5, 0, 1, 1, Width - 2, 1)
  256.  
  257. e.Graphics.DrawImage(B.Clone, 0, 0)
  258. End Using
  259. End Using
  260. End Sub
  261. End Class
  262. Public Class MProgress : Inherits Control
  263. Private _Value As Integer
  264. Public Property Value() As Integer
  265. Get
  266. Return _Value
  267. End Get
  268. Set(ByVal value As Integer)
  269. _Value = value : Invalidate()
  270. End Set
  271. End Property
  272. Private _Maximum As Integer = 100
  273. Public Property Maximum() As Integer
  274. Get
  275. Return _Maximum
  276. End Get
  277. Set(ByVal value As Integer)
  278. If value = 0 Then value = 1
  279. _Maximum = value : Invalidate()
  280. End Set
  281. End Property
  282. Dim C1 As Color = Color.FromArgb(31, 31, 31), C2 As Color = Color.FromArgb(41, 41, 41), C3 As Color = Color.FromArgb(51, 51, 51), _
  283. C4 As Color = Color.FromArgb(0, 0, 0, 0), C5 As Color = Color.FromArgb(25, 255, 255, 255)
  284. Protected Overrides Sub OnPaintBackground(ByVal pevent As System.Windows.Forms.PaintEventArgs)
  285. End Sub
  286. Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  287. Dim V As Integer = Width * _Value / _Maximum
  288. Using B As New Bitmap(Width, Height)
  289. Using G = Graphics.FromImage(B)
  290. Draw.Gradient(G, C2, C3, 1, 1, Width - 2, Height - 2)
  291. G.DrawRectangle(New Pen(C2), 1, 1, V - 3, Height - 3)
  292. Draw.Gradient(G, C3, C2, 2, 2, V - 4, Height - 4)
  293.  
  294. G.DrawRectangle(New Pen(C1), 0, 0, Width - 1, Height - 1)
  295.  
  296. e.Graphics.DrawImage(B.Clone, 0, 0)
  297. End Using
  298. End Using
  299. End Sub
  300. End Class
  301. 'Electron Theme
  302. Public Class ETheme : Inherits Control
  303. Private _TitleHeight As Integer = 25
  304. Public Property TitleHeight() As Integer
  305. Get
  306. Return _TitleHeight
  307. End Get
  308. Set(ByVal v As Integer)
  309. If v > Height Then v = Height
  310. If v < 2 Then Height = 1
  311. _TitleHeight = v : Invalidate()
  312. End Set
  313. End Property
  314. Private _TitleAlign As HorizontalAlignment = 2
  315. Public Property TitleAlign() As HorizontalAlignment
  316. Get
  317. Return _TitleAlign
  318. End Get
  319. Set(ByVal v As HorizontalAlignment)
  320. _TitleAlign = v : Invalidate()
  321. End Set
  322. End Property
  323. Protected Overrides Sub OnHandleCreated(ByVal e As System.EventArgs)
  324. Dock = 5
  325. If TypeOf Parent Is Form Then CType(Parent, Form).FormBorderStyle = 0
  326. MyBase.OnHandleCreated(e)
  327. End Sub
  328. Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
  329. If New Rectangle(Parent.Location.X, Parent.Location.Y, Width - 1, _TitleHeight - 1).IntersectsWith(New Rectangle(MousePosition.X, MousePosition.Y, 1, 1)) Then
  330. Capture = False : Dim M = Message.Create(Parent.Handle, 161, 2, 0) : DefWndProc(M)
  331. End If : MyBase.OnMouseDown(e)
  332. End Sub
  333. Dim C1 As Color = Color.FromArgb(0, 70, 114), C2 As Color = Color.FromArgb(0, 47, 78), C3 As Color = Color.FromArgb(0, 34, 57), _
  334. C4 As Color = Color.FromArgb(0, 30, 50)
  335. Protected Overrides Sub OnPaintBackground(ByVal pevent As System.Windows.Forms.PaintEventArgs)
  336. End Sub
  337. Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  338. Using B As New Bitmap(Width, Height)
  339. Using G = Graphics.FromImage(B)
  340. G.Clear(C3)
  341.  
  342. Draw.Blend(G, C2, C3, C1, 0.5, 1, 0, 0, Width, _TitleHeight)
  343.  
  344. G.FillRectangle(New SolidBrush(Color.FromArgb(15, 255, 255, 255)), 1, 1, Width - 2, CInt(_TitleHeight / 2) - 2)
  345. G.DrawRectangle(New Pen(Color.FromArgb(35, 255, 255, 255)), 1, 1, Width - 3, _TitleHeight - 2)
  346.  
  347. Dim S = G.MeasureString(Text, Font), O = 6
  348. If _TitleAlign = 2 Then O = Width / 2 - S.Width / 2
  349. If _TitleAlign = 1 Then O = Width - S.Width - 14
  350. Dim V = CInt(_TitleHeight / 2 - (S.Height + 4) / 2)
  351.  
  352. Draw.Gradient(G, C3, C2, O, V, S.Width + 8, S.Height + 4)
  353. G.DrawRectangle(New Pen(C3), O, V, S.Width + 7, S.Height + 3)
  354.  
  355. Dim R As New Rectangle(O + 4, CInt(_TitleHeight / 2 - S.Height / 2), S.Width, S.Height)
  356. Using T As New LinearGradientBrush(R, C1, C2, LinearGradientMode.Vertical)
  357. G.DrawString(Text, Font, T, R)
  358. End Using
  359.  
  360. G.DrawRectangle(New Pen(C1), 1, _TitleHeight + 1, Width - 3, Height - _TitleHeight - 3)
  361.  
  362. G.DrawLine(New Pen(C4), 0, _TitleHeight, Width, _TitleHeight)
  363. G.DrawRectangle(New Pen(C4), 0, 0, Width - 1, Height - 1)
  364. e.Graphics.DrawImage(B.Clone, 0, 0)
  365. End Using
  366. End Using
  367. End Sub
  368. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement