Guest User

Untitled

a guest
Jun 20th, 2011
463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.27 KB | None | 0 0
  1. Imports System.Drawing.Drawing2D
  2. Imports System.ComponentModel
  3. Imports System.Runtime.InteropServices
  4. 'Author: TheDarky
  5. 'Credits: Aeonhack [Themebase and Tutorials :)]
  6. 'Version: 0.1
  7. MustInherit Class Theme
  8. Inherits ContainerControl
  9.  
  10. #Region " Initialization "
  11.  
  12. Protected G As Graphics
  13. Sub New()
  14. SetStyle(DirectCast(139270, ControlStyles), True)
  15. End Sub
  16.  
  17. Private ParentIsForm As Boolean
  18. Protected Overrides Sub OnHandleCreated(ByVal e As EventArgs)
  19. Dock = DockStyle.Fill
  20. ParentIsForm = TypeOf Parent Is Form
  21. If ParentIsForm Then
  22. If Not _TransparencyKey = Color.Empty Then ParentForm.TransparencyKey = _TransparencyKey
  23. ParentForm.FormBorderStyle = FormBorderStyle.None
  24. End If
  25. MyBase.OnHandleCreated(e)
  26. End Sub
  27.  
  28. Overrides Property Text() As String
  29. Get
  30. Return MyBase.Text
  31. End Get
  32. Set(ByVal v As String)
  33. MyBase.Text = v
  34. Invalidate()
  35. End Set
  36. End Property
  37. #End Region
  38.  
  39. #Region " Sizing and Movement "
  40.  
  41. Private _Resizable As Boolean = True
  42. Property Resizable() As Boolean
  43. Get
  44. Return _Resizable
  45. End Get
  46. Set(ByVal value As Boolean)
  47. _Resizable = value
  48. End Set
  49. End Property
  50.  
  51. Private _MoveHeight As Integer = 24
  52. Property MoveHeight() As Integer
  53. Get
  54. Return _MoveHeight
  55. End Get
  56. Set(ByVal v As Integer)
  57. _MoveHeight = v
  58. Header = New Rectangle(7, 7, Width - 14, _MoveHeight - 7)
  59. End Set
  60. End Property
  61.  
  62. Private Flag As IntPtr
  63. Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
  64. If Not e.Button = MouseButtons.Left Then Return
  65. If ParentIsForm Then If ParentForm.WindowState = FormWindowState.Maximized Then Return
  66.  
  67. If Header.Contains(e.Location) Then
  68. Flag = New IntPtr(2)
  69. ElseIf Current.Position = 0 Or Not _Resizable Then
  70. Return
  71. Else
  72. Flag = New IntPtr(Current.Position)
  73. End If
  74.  
  75. Capture = False
  76. DefWndProc(Message.Create(Parent.Handle, 161, Flag, Nothing))
  77.  
  78. MyBase.OnMouseDown(e)
  79. End Sub
  80.  
  81. Private Structure Pointer
  82. ReadOnly Cursor As Cursor, Position As Byte
  83. Sub New(ByVal c As Cursor, ByVal p As Byte)
  84. Cursor = c
  85. Position = p
  86. End Sub
  87. End Structure
  88.  
  89. Private F1, F2, F3, F4 As Boolean, PTC As Point
  90. Private Function GetPointer() As Pointer
  91. PTC = PointToClient(MousePosition)
  92. F1 = PTC.X < 7
  93. F2 = PTC.X > Width - 7
  94. F3 = PTC.Y < 7
  95. F4 = PTC.Y > Height - 7
  96.  
  97. If F1 And F3 Then Return New Pointer(Cursors.SizeNWSE, 13)
  98. If F1 And F4 Then Return New Pointer(Cursors.SizeNESW, 16)
  99. If F2 And F3 Then Return New Pointer(Cursors.SizeNESW, 14)
  100. If F2 And F4 Then Return New Pointer(Cursors.SizeNWSE, 17)
  101. If F1 Then Return New Pointer(Cursors.SizeWE, 10)
  102. If F2 Then Return New Pointer(Cursors.SizeWE, 11)
  103. If F3 Then Return New Pointer(Cursors.SizeNS, 12)
  104. If F4 Then Return New Pointer(Cursors.SizeNS, 15)
  105. Return New Pointer(Cursors.Default, 0)
  106. End Function
  107.  
  108. Private Current, Pending As Pointer
  109. Private Sub SetCurrent()
  110. Pending = GetPointer()
  111. If Current.Position = Pending.Position Then Return
  112. Current = GetPointer()
  113. Cursor = Current.Cursor
  114. End Sub
  115.  
  116. Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
  117. If _Resizable Then SetCurrent()
  118. MyBase.OnMouseMove(e)
  119. End Sub
  120.  
  121. Protected Header As Rectangle
  122. Protected Overrides Sub OnSizeChanged(ByVal e As EventArgs)
  123. If Width = 0 OrElse Height = 0 Then Return
  124. Header = New Rectangle(7, 7, Width - 14, _MoveHeight - 7)
  125. Invalidate()
  126. MyBase.OnSizeChanged(e)
  127. End Sub
  128.  
  129. #End Region
  130.  
  131. #Region " Convienence "
  132.  
  133. MustOverride Sub PaintHook()
  134. Protected NotOverridable Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  135. If Width = 0 OrElse Height = 0 Then Return
  136. G = e.Graphics
  137. PaintHook()
  138. End Sub
  139.  
  140. Private _TransparencyKey As Color
  141. Property TransparencyKey() As Color
  142. Get
  143. Return _TransparencyKey
  144. End Get
  145. Set(ByVal v As Color)
  146. _TransparencyKey = v
  147. Invalidate()
  148. End Set
  149. End Property
  150.  
  151. Private _Image As Image
  152. Property Image() As Image
  153. Get
  154. Return _Image
  155. End Get
  156. Set(ByVal value As Image)
  157. _Image = value
  158. Invalidate()
  159. End Set
  160. End Property
  161. ReadOnly Property ImageWidth() As Integer
  162. Get
  163. If _Image Is Nothing Then Return 0
  164. Return _Image.Width
  165. End Get
  166. End Property
  167.  
  168. Private _Size As Size
  169. Private _Rectangle As Rectangle
  170. Private _Gradient As LinearGradientBrush
  171. Private _Brush As SolidBrush
  172.  
  173. Protected Sub DrawCorners(ByVal c As Color, ByVal rect As Rectangle)
  174. _Brush = New SolidBrush(c)
  175. G.FillRectangle(_Brush, rect.X, rect.Y, 1, 1)
  176. G.FillRectangle(_Brush, rect.X + (rect.Width - 1), rect.Y, 1, 1)
  177. G.FillRectangle(_Brush, rect.X, rect.Y + (rect.Height - 1), 1, 1)
  178. G.FillRectangle(_Brush, rect.X + (rect.Width - 1), rect.Y + (rect.Height - 1), 1, 1)
  179. End Sub
  180.  
  181. Protected Sub DrawBorders(ByVal p1 As Pen, ByVal p2 As Pen, ByVal rect As Rectangle)
  182. G.DrawRectangle(p1, rect.X, rect.Y, rect.Width - 1, rect.Height - 1)
  183. G.DrawRectangle(p2, rect.X + 1, rect.Y + 1, rect.Width - 3, rect.Height - 3)
  184. End Sub
  185.  
  186. Protected Sub DrawText(ByVal a As HorizontalAlignment, ByVal c As Color, ByVal x As Integer)
  187. DrawText(a, c, x, 0)
  188. End Sub
  189. Protected Sub DrawText(ByVal a As HorizontalAlignment, ByVal c As Color, ByVal x As Integer, ByVal y As Integer)
  190. If String.IsNullOrEmpty(Text) Then Return
  191. _Size = G.MeasureString(Text, Font).ToSize
  192. _Brush = New SolidBrush(c)
  193.  
  194. Select Case a
  195. Case HorizontalAlignment.Left
  196. G.DrawString(Text, Font, _Brush, x, _MoveHeight \ 2 - _Size.Height \ 2 + y)
  197. Case HorizontalAlignment.Right
  198. G.DrawString(Text, Font, _Brush, Width - _Size.Width - x, _MoveHeight \ 2 - _Size.Height \ 2 + y)
  199. Case HorizontalAlignment.Center
  200. G.DrawString(Text, Font, _Brush, Width \ 2 - _Size.Width \ 2 + x, _MoveHeight \ 2 - _Size.Height \ 2 + y)
  201. End Select
  202. End Sub
  203.  
  204. Protected Sub DrawIcon(ByVal a As HorizontalAlignment, ByVal x As Integer)
  205. DrawIcon(a, x, 0)
  206. End Sub
  207. Protected Sub DrawIcon(ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  208. If _Image Is Nothing Then Return
  209. Select Case a
  210. Case HorizontalAlignment.Left
  211. G.DrawImage(_Image, x, _MoveHeight \ 2 - _Image.Height \ 2 + y)
  212. Case HorizontalAlignment.Right
  213. G.DrawImage(_Image, Width - _Image.Width - x, _MoveHeight \ 2 - _Image.Height \ 2 + y)
  214. Case HorizontalAlignment.Center
  215. G.DrawImage(_Image, Width \ 2 - _Image.Width \ 2, _MoveHeight \ 2 - _Image.Height \ 2)
  216. End Select
  217. End Sub
  218.  
  219. 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)
  220. _Rectangle = New Rectangle(x, y, width, height)
  221. _Gradient = New LinearGradientBrush(_Rectangle, c1, c2, angle)
  222. G.FillRectangle(_Gradient, _Rectangle)
  223. End Sub
  224.  
  225. #End Region
  226.  
  227. End Class
  228. MustInherit Class ThemeControl
  229. Inherits Control
  230.  
  231. #Region " Initialization "
  232.  
  233. Protected G As Graphics, B As Bitmap
  234. Sub New()
  235. SetStyle(DirectCast(139270, ControlStyles), True)
  236. B = New Bitmap(1, 1)
  237. G = Graphics.FromImage(B)
  238. End Sub
  239.  
  240. Sub AllowTransparent()
  241. SetStyle(ControlStyles.Opaque, False)
  242. SetStyle(ControlStyles.SupportsTransparentBackColor, True)
  243. End Sub
  244.  
  245. Overrides Property Text() As String
  246. Get
  247. Return MyBase.Text
  248. End Get
  249. Set(ByVal v As String)
  250. MyBase.Text = v
  251. Invalidate()
  252. End Set
  253. End Property
  254. #End Region
  255.  
  256. #Region " Mouse Handling "
  257.  
  258. Protected Enum State As Byte
  259. MouseNone = 0
  260. MouseOver = 1
  261. MouseDown = 2
  262. End Enum
  263.  
  264. Protected MouseState As State
  265. Protected Overrides Sub OnMouseLeave(ByVal e As EventArgs)
  266. ChangeMouseState(State.MouseNone)
  267. MyBase.OnMouseLeave(e)
  268. End Sub
  269. Protected Overrides Sub OnMouseEnter(ByVal e As EventArgs)
  270. ChangeMouseState(State.MouseOver)
  271. MyBase.OnMouseEnter(e)
  272. End Sub
  273. Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
  274. ChangeMouseState(State.MouseOver)
  275. MyBase.OnMouseUp(e)
  276. End Sub
  277. Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
  278. If e.Button = MouseButtons.Left Then ChangeMouseState(State.MouseDown)
  279. MyBase.OnMouseDown(e)
  280. End Sub
  281.  
  282. Private Sub ChangeMouseState(ByVal e As State)
  283. MouseState = e
  284. Invalidate()
  285. End Sub
  286.  
  287. #End Region
  288.  
  289. #Region " Convienence "
  290.  
  291. MustOverride Sub PaintHook()
  292. Protected NotOverridable Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  293. If Width = 0 OrElse Height = 0 Then Return
  294. PaintHook()
  295. e.Graphics.DrawImage(B, 0, 0)
  296. End Sub
  297.  
  298. Protected Overrides Sub OnSizeChanged(ByVal e As EventArgs)
  299. If Not Width = 0 AndAlso Not Height = 0 Then
  300. B = New Bitmap(Width, Height)
  301. G = Graphics.FromImage(B)
  302. Invalidate()
  303. End If
  304. MyBase.OnSizeChanged(e)
  305. End Sub
  306.  
  307. Private _NoRounding As Boolean
  308. Property NoRounding() As Boolean
  309. Get
  310. Return _NoRounding
  311. End Get
  312. Set(ByVal v As Boolean)
  313. _NoRounding = v
  314. Invalidate()
  315. End Set
  316. End Property
  317.  
  318. Private _Image As Image
  319. Property Image() As Image
  320. Get
  321. Return _Image
  322. End Get
  323. Set(ByVal value As Image)
  324. _Image = value
  325. Invalidate()
  326. End Set
  327. End Property
  328. ReadOnly Property ImageWidth() As Integer
  329. Get
  330. If _Image Is Nothing Then Return 0
  331. Return _Image.Width
  332. End Get
  333. End Property
  334. ReadOnly Property ImageTop() As Integer
  335. Get
  336. If _Image Is Nothing Then Return 0
  337. Return Height \ 2 - _Image.Height \ 2
  338. End Get
  339. End Property
  340.  
  341. Private _Size As Size
  342. Private _Rectangle As Rectangle
  343. Private _Gradient As LinearGradientBrush
  344. Private _Brush As SolidBrush
  345.  
  346. Protected Sub DrawCorners(ByVal c As Color, ByVal rect As Rectangle)
  347. If _NoRounding Then Return
  348.  
  349. B.SetPixel(rect.X, rect.Y, c)
  350. B.SetPixel(rect.X + (rect.Width - 1), rect.Y, c)
  351. B.SetPixel(rect.X, rect.Y + (rect.Height - 1), c)
  352. B.SetPixel(rect.X + (rect.Width - 1), rect.Y + (rect.Height - 1), c)
  353. End Sub
  354.  
  355. Protected Sub DrawBorders(ByVal p1 As Pen, ByVal p2 As Pen, ByVal rect As Rectangle)
  356. G.DrawRectangle(p1, rect.X, rect.Y, rect.Width - 1, rect.Height - 1)
  357. G.DrawRectangle(p2, rect.X + 1, rect.Y + 1, rect.Width - 3, rect.Height - 3)
  358. End Sub
  359.  
  360. Protected Sub DrawText(ByVal a As HorizontalAlignment, ByVal c As Color, ByVal x As Integer)
  361. DrawText(a, c, x, 0)
  362. End Sub
  363. Protected Sub DrawText(ByVal a As HorizontalAlignment, ByVal c As Color, ByVal x As Integer, ByVal y As Integer)
  364. If String.IsNullOrEmpty(Text) Then Return
  365. _Size = G.MeasureString(Text, Font).ToSize
  366. _Brush = New SolidBrush(c)
  367.  
  368. Select Case a
  369. Case HorizontalAlignment.Left
  370. G.DrawString(Text, Font, _Brush, x, Height \ 2 - _Size.Height \ 2 + y)
  371. Case HorizontalAlignment.Right
  372. G.DrawString(Text, Font, _Brush, Width - _Size.Width - x, Height \ 2 - _Size.Height \ 2 + y)
  373. Case HorizontalAlignment.Center
  374. G.DrawString(Text, Font, _Brush, Width \ 2 - _Size.Width \ 2 + x, Height \ 2 - _Size.Height \ 2 + y)
  375. End Select
  376. End Sub
  377.  
  378. Protected Sub DrawIcon(ByVal a As HorizontalAlignment, ByVal x As Integer)
  379. DrawIcon(a, x, 0)
  380. End Sub
  381. Protected Sub DrawIcon(ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  382. If _Image Is Nothing Then Return
  383. Select Case a
  384. Case HorizontalAlignment.Left
  385. G.DrawImage(_Image, x, Height \ 2 - _Image.Height \ 2 + y)
  386. Case HorizontalAlignment.Right
  387. G.DrawImage(_Image, Width - _Image.Width - x, Height \ 2 - _Image.Height \ 2 + y)
  388. Case HorizontalAlignment.Center
  389. G.DrawImage(_Image, Width \ 2 - _Image.Width \ 2, Height \ 2 - _Image.Height \ 2)
  390. End Select
  391. End Sub
  392.  
  393. 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)
  394. _Rectangle = New Rectangle(x, y, width, height)
  395. _Gradient = New LinearGradientBrush(_Rectangle, c1, c2, angle)
  396. G.FillRectangle(_Gradient, _Rectangle)
  397. End Sub
  398. #End Region
  399.  
  400. End Class
  401. MustInherit Class ThemeContainerControl
  402. Inherits ContainerControl
  403.  
  404. #Region " Initialization "
  405.  
  406. Protected G As Graphics, B As Bitmap
  407. Sub New()
  408. SetStyle(DirectCast(139270, ControlStyles), True)
  409. B = New Bitmap(1, 1)
  410. G = Graphics.FromImage(B)
  411. End Sub
  412.  
  413. Sub AllowTransparent()
  414. SetStyle(ControlStyles.Opaque, False)
  415. SetStyle(ControlStyles.SupportsTransparentBackColor, True)
  416. End Sub
  417.  
  418. #End Region
  419. #Region " Convienence "
  420.  
  421. MustOverride Sub PaintHook()
  422. Protected NotOverridable Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  423. If Width = 0 OrElse Height = 0 Then Return
  424. PaintHook()
  425. e.Graphics.DrawImage(B, 0, 0)
  426. End Sub
  427.  
  428. Protected Overrides Sub OnSizeChanged(ByVal e As EventArgs)
  429. If Not Width = 0 AndAlso Not Height = 0 Then
  430. B = New Bitmap(Width, Height)
  431. G = Graphics.FromImage(B)
  432. Invalidate()
  433. End If
  434. MyBase.OnSizeChanged(e)
  435. End Sub
  436.  
  437. Private _NoRounding As Boolean
  438. Property NoRounding() As Boolean
  439. Get
  440. Return _NoRounding
  441. End Get
  442. Set(ByVal v As Boolean)
  443. _NoRounding = v
  444. Invalidate()
  445. End Set
  446. End Property
  447.  
  448. Private _Rectangle As Rectangle
  449. Private _Gradient As LinearGradientBrush
  450.  
  451. Protected Sub DrawCorners(ByVal c As Color, ByVal rect As Rectangle)
  452. If _NoRounding Then Return
  453. B.SetPixel(rect.X, rect.Y, c)
  454. B.SetPixel(rect.X + (rect.Width - 1), rect.Y, c)
  455. B.SetPixel(rect.X, rect.Y + (rect.Height - 1), c)
  456. B.SetPixel(rect.X + (rect.Width - 1), rect.Y + (rect.Height - 1), c)
  457. End Sub
  458.  
  459. Protected Sub DrawBorders(ByVal p1 As Pen, ByVal p2 As Pen, ByVal rect As Rectangle)
  460. G.DrawRectangle(p1, rect.X, rect.Y, rect.Width - 1, rect.Height - 1)
  461. G.DrawRectangle(p2, rect.X + 1, rect.Y + 1, rect.Width - 3, rect.Height - 3)
  462. End Sub
  463.  
  464. 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)
  465. _Rectangle = New Rectangle(x, y, width, height)
  466. _Gradient = New LinearGradientBrush(_Rectangle, c1, c2, angle)
  467. G.FillRectangle(_Gradient, _Rectangle)
  468. End Sub
  469. #End Region
  470.  
  471. End Class
  472.  
  473. Class eTheme
  474. Inherits Theme
  475. Sub New()
  476. BackColor = Color.FromArgb(53, 53, 53)
  477. MoveHeight = 30
  478. End Sub
  479. Overrides Sub PaintHook()
  480.  
  481. G.Clear(Color.FromArgb(53, 53, 53))
  482. DrawGradient(Color.FromArgb(50, 50, 50), Color.FromArgb(50, 50, 50), 0, 1, Width, 14, 90S)
  483. DrawGradient(Color.FromArgb(29, 29, 29), Color.FromArgb(29, 29, 29), 2, 16, Width, 14, 90S)
  484. G.DrawLine(Pens.Black, 0, 30, Width, 30)
  485. DrawBorders(Pens.Gray, Pens.Black, ClientRectangle)
  486. DrawText(HorizontalAlignment.Center, Color.Gray, 0)
  487.  
  488. End Sub
  489. End Class
  490.  
  491. Class eButton
  492. Inherits ThemeControl
  493. Overrides Sub PaintHook()
  494. Select Case MouseState
  495. Case State.MouseNone
  496. G.Clear(Color.FromArgb(49, 49, 49))
  497. DrawGradient(Color.FromArgb(50, 50, 50), Color.FromArgb(40, 40, 40), ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width, ClientRectangle.Height, 90S)
  498. Case State.MouseDown
  499. G.Clear(Color.FromArgb(49, 49, 49))
  500. DrawGradient(Color.FromArgb(40, 40, 40), Color.FromArgb(50, 50, 50), ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width, ClientRectangle.Height, 90S)
  501. Case State.MouseOver
  502. G.Clear(Color.FromArgb(49, 49, 49))
  503. DrawGradient(Color.FromArgb(60, 60, 60), Color.FromArgb(50, 50, 50), ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width, ClientRectangle.Height, 90S)
  504. End Select
  505. DrawText(HorizontalAlignment.Center, Color.Gray, 0)
  506. DrawBorders(Pens.Black, Pens.DimGray, ClientRectangle)
  507. DrawCorners(Color.FromArgb(53, 53, 53), ClientRectangle)
  508.  
  509. End Sub
  510. End Class
  511.  
  512. Class eGroupBox
  513. Inherits ThemeContainerControl
  514. Sub New()
  515. AllowTransparent()
  516. End Sub
  517. Overrides Sub PaintHook()
  518. G.Clear(Color.FromArgb(45, 45, 45))
  519. DrawBorders(New Pen(Color.FromArgb(25, Color.White)), New Pen(Color.FromArgb(90, Color.Black)), ClientRectangle)
  520. DrawCorners(BackColor, ClientRectangle)
  521. End Sub
  522. End Class
  523.  
  524. Class eLabel
  525. Inherits ThemeControl
  526. Overrides Sub PaintHook()
  527. G.Clear(BackColor)
  528. DrawText(HorizontalAlignment.Center, Color.Gray, 0)
  529. End Sub
  530. End Class
  531.  
  532. Class eSeperator
  533. Inherits ThemeControl
  534. Overrides Sub PaintHook()
  535. G.Clear(BackColor)
  536. G.DrawLine(Pens.Gray, 0, CInt(ClientRectangle.Y \ 2), Width, 0)
  537. End Sub
  538. End Class
Advertisement
Add Comment
Please, Sign In to add comment