xrahitel

cod

Dec 31st, 2017
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 50.17 KB | None | 0 0
  1. Imports System, System.IO, System.Collections.Generic
  2. Imports System.Drawing, System.Drawing.Drawing2D
  3. Imports System.ComponentModel, System.Windows.Forms
  4.  
  5. '------------------
  6. 'Creator: codeby.net
  7. 'Theme By: REDTEAM
  8. 'Created: 8/2/2017
  9. 'Changed: 8/31/2017
  10. 'Version: 1.5.1
  11. 'Released: 9/18/2017
  12. '------------------
  13.  
  14. Enum MouseState As Byte
  15. None = 0
  16. Over = 1
  17. Down = 2
  18. Block = 3
  19. End Enum
  20.  
  21. Class Bloom
  22.  
  23. Private _Name As String
  24. Property Name() As String
  25. Get
  26. Return _Name
  27. End Get
  28. Set(ByVal value As String)
  29. _Name = value
  30. End Set
  31. End Property
  32.  
  33. Private _Value As Color
  34. Property Value() As Color
  35. Get
  36. Return _Value
  37. End Get
  38. Set(ByVal value As Color)
  39. _Value = value
  40. End Set
  41. End Property
  42.  
  43. Private _Pen As Pen
  44. Public Property Pen() As Pen
  45. Get
  46. Return _Pen
  47. End Get
  48. Set(ByVal value As Pen)
  49. _Pen = value
  50. End Set
  51. End Property
  52.  
  53. Private _Brush As Brush
  54. Public Property Brush() As Brush
  55. Get
  56. Return _Brush
  57. End Get
  58. Set(ByVal value As Brush)
  59. _Brush = value
  60. End Set
  61. End Property
  62.  
  63. Sub New(ByVal name As String, ByVal value As Color)
  64. _Name = name
  65. _Value = value
  66. _Pen = New Pen(value)
  67. _Brush = New SolidBrush(value)
  68. End Sub
  69. End Class
  70.  
  71. MustInherit Class ThemeContainer151
  72. Inherits ContainerControl
  73.  
  74. Protected G As Graphics
  75.  
  76. Sub New()
  77. SetStyle(DirectCast(139270, ControlStyles), True)
  78. _ImageSize = Size.Empty
  79.  
  80. MeasureBitmap = New Bitmap(1, 1)
  81. MeasureGraphics = Graphics.FromImage(MeasureBitmap)
  82.  
  83. Font = New Font("Verdana", 8S)
  84.  
  85. InvalidateCustimization()
  86. End Sub
  87.  
  88. Protected Overrides Sub SetBoundsCore(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal specified As BoundsSpecified)
  89. If Not _LockWidth = 0 Then width = _LockWidth
  90. If Not _LockHeight = 0 Then height = _LockHeight
  91. MyBase.SetBoundsCore(x, y, width, height, specified)
  92. End Sub
  93.  
  94. Private Header As Rectangle
  95. Protected NotOverridable Overrides Sub OnSizeChanged(ByVal e As EventArgs)
  96. MyBase.OnSizeChanged(e)
  97. If _Movable AndAlso Not _ControlMode Then Header = New Rectangle(7, 7, Width - 14, _MoveHeight - 7)
  98. Invalidate()
  99. End Sub
  100.  
  101. Protected NotOverridable Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  102. If Width = 0 OrElse Height = 0 Then Return
  103. G = e.Graphics
  104. PaintHook()
  105. End Sub
  106.  
  107. Protected NotOverridable Overrides Sub OnHandleCreated(ByVal e As EventArgs)
  108. InitializeMessages()
  109. InvalidateCustimization()
  110. ColorHook()
  111.  
  112. _IsParentForm = TypeOf Parent Is Form
  113. If Not _ControlMode Then Dock = DockStyle.Fill
  114.  
  115. If Not _LockWidth = 0 Then Width = _LockWidth
  116. If Not _LockHeight = 0 Then Height = _LockHeight
  117. If Not BackColorWait = Nothing Then BackColor = BackColorWait
  118.  
  119. If _IsParentForm AndAlso Not _ControlMode Then
  120. ParentForm.FormBorderStyle = _BorderStyle
  121. ParentForm.TransparencyKey = _TransparencyKey
  122. End If
  123.  
  124. OnCreation()
  125. MyBase.OnHandleCreated(e)
  126. End Sub
  127.  
  128. Protected Overridable Sub OnCreation()
  129. End Sub
  130.  
  131. #Region " Sizing and Movement "
  132.  
  133. Protected State As MouseState
  134. Private Sub SetState(ByVal current As MouseState)
  135. State = current
  136. Invalidate()
  137. End Sub
  138.  
  139. Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
  140. If _Sizable AndAlso Not _ControlMode Then InvalidateMouse()
  141. MyBase.OnMouseMove(e)
  142. End Sub
  143.  
  144. Protected Overrides Sub OnEnabledChanged(ByVal e As EventArgs)
  145. If Enabled Then SetState(MouseState.None) Else SetState(MouseState.Block)
  146. MyBase.OnEnabledChanged(e)
  147. End Sub
  148.  
  149. Protected Overrides Sub OnMouseEnter(ByVal e As EventArgs)
  150. SetState(MouseState.Over)
  151. MyBase.OnMouseEnter(e)
  152. End Sub
  153.  
  154. Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
  155. SetState(MouseState.Over)
  156. MyBase.OnMouseUp(e)
  157. End Sub
  158.  
  159. Protected Overrides Sub OnMouseLeave(ByVal e As EventArgs)
  160. SetState(MouseState.None)
  161.  
  162. If _Sizable AndAlso Not _ControlMode AndAlso GetChildAtPoint(PointToClient(MousePosition)) IsNot Nothing Then
  163. Cursor = Cursors.Default
  164. Previous = 0
  165. End If
  166.  
  167. MyBase.OnMouseLeave(e)
  168. End Sub
  169.  
  170. Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
  171. MyBase.OnMouseDown(e)
  172.  
  173. If Not e.Button = Windows.Forms.MouseButtons.Left Then Return
  174. SetState(MouseState.Down)
  175.  
  176. If _IsParentForm AndAlso ParentForm.WindowState = FormWindowState.Maximized OrElse _ControlMode Then Return
  177.  
  178. If _Movable AndAlso Header.Contains(e.Location) Then
  179. Capture = False
  180. DefWndProc(Messages(0))
  181. ElseIf _Sizable AndAlso Not Previous = 0 Then
  182. Capture = False
  183. DefWndProc(Messages(Previous))
  184. End If
  185. End Sub
  186.  
  187. Private GetIndexPoint As Point
  188. Private B1, B2, B3, B4 As Boolean
  189. Private Function GetIndex() As Integer
  190. GetIndexPoint = PointToClient(MousePosition)
  191. B1 = GetIndexPoint.X < 7
  192. B2 = GetIndexPoint.X > Width - 7
  193. B3 = GetIndexPoint.Y < 7
  194. B4 = GetIndexPoint.Y > Height - 7
  195.  
  196. If B1 AndAlso B3 Then Return 4
  197. If B1 AndAlso B4 Then Return 7
  198. If B2 AndAlso B3 Then Return 5
  199. If B2 AndAlso B4 Then Return 8
  200. If B1 Then Return 1
  201. If B2 Then Return 2
  202. If B3 Then Return 3
  203. If B4 Then Return 6
  204. Return 0
  205. End Function
  206.  
  207. Private Current, Previous As Integer
  208. Private Sub InvalidateMouse()
  209. Current = GetIndex()
  210. If Current = Previous Then Return
  211.  
  212. Previous = Current
  213. Select Case Previous
  214. Case 0
  215. Cursor = Cursors.Default
  216. Case 1, 2
  217. Cursor = Cursors.SizeWE
  218. Case 3, 6
  219. Cursor = Cursors.SizeNS
  220. Case 4, 8
  221. Cursor = Cursors.SizeNWSE
  222. Case 5, 7
  223. Cursor = Cursors.SizeNESW
  224. End Select
  225. End Sub
  226.  
  227. Private Messages(8) As Message
  228. Private Sub InitializeMessages()
  229. Messages(0) = Message.Create(Parent.Handle, 161, New IntPtr(2), IntPtr.Zero)
  230. For I As Integer = 1 To 8
  231. Messages(I) = Message.Create(Parent.Handle, 161, New IntPtr(I + 9), IntPtr.Zero)
  232. Next
  233. End Sub
  234.  
  235. #End Region
  236.  
  237.  
  238. #Region " Property Overrides "
  239.  
  240. Private BackColorWait As Color
  241. Overrides Property BackColor() As Color
  242. Get
  243. Return MyBase.BackColor
  244. End Get
  245. Set(ByVal value As Color)
  246. If IsHandleCreated Then
  247. If Not _ControlMode Then Parent.BackColor = value
  248. MyBase.BackColor = value
  249. Else
  250. BackColorWait = value
  251. End If
  252. End Set
  253. End Property
  254.  
  255. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  256. Overrides Property ForeColor() As Color
  257. Get
  258. Return Color.Empty
  259. End Get
  260. Set(ByVal value As Color)
  261. End Set
  262. End Property
  263. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  264. Overrides Property BackgroundImage() As Image
  265. Get
  266. Return Nothing
  267. End Get
  268. Set(ByVal value As Image)
  269. End Set
  270. End Property
  271. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  272. Overrides Property BackgroundImageLayout() As ImageLayout
  273. Get
  274. Return ImageLayout.None
  275. End Get
  276. Set(ByVal value As ImageLayout)
  277. End Set
  278. End Property
  279.  
  280. Overrides Property Text() As String
  281. Get
  282. Return MyBase.Text
  283. End Get
  284. Set(ByVal value As String)
  285. MyBase.Text = value
  286. Invalidate()
  287. End Set
  288. End Property
  289.  
  290. Overrides Property Font() As Font
  291. Get
  292. Return MyBase.Font
  293. End Get
  294. Set(ByVal value As Font)
  295. MyBase.Font = value
  296. Invalidate()
  297. End Set
  298. End Property
  299.  
  300. #End Region
  301.  
  302. #Region " Properties "
  303.  
  304. Private _Movable As Boolean = True
  305. Property Movable() As Boolean
  306. Get
  307. Return _Movable
  308. End Get
  309. Set(ByVal value As Boolean)
  310. _Movable = value
  311. End Set
  312. End Property
  313.  
  314. Private _Sizable As Boolean = True
  315. Property Sizable() As Boolean
  316. Get
  317. Return _Sizable
  318. End Get
  319. Set(ByVal value As Boolean)
  320. _Sizable = value
  321. End Set
  322. End Property
  323.  
  324. Private _MoveHeight As Integer = 24
  325. Protected Property MoveHeight() As Integer
  326. Get
  327. Return _MoveHeight
  328. End Get
  329. Set(ByVal v As Integer)
  330. If v < 8 Then Return
  331. Header = New Rectangle(7, 7, Width - 14, v - 7)
  332. _MoveHeight = v
  333. Invalidate()
  334. End Set
  335. End Property
  336.  
  337. Private _ControlMode As Boolean
  338. Protected Property ControlMode() As Boolean
  339. Get
  340. Return _ControlMode
  341. End Get
  342. Set(ByVal v As Boolean)
  343. _ControlMode = v
  344. End Set
  345. End Property
  346.  
  347. Private _TransparencyKey As Color
  348. Property TransparencyKey() As Color
  349. Get
  350. If _IsParentForm AndAlso Not _ControlMode Then Return ParentForm.TransparencyKey Else Return _TransparencyKey
  351. End Get
  352. Set(ByVal value As Color)
  353. If _IsParentForm AndAlso Not _ControlMode Then ParentForm.TransparencyKey = value
  354. _TransparencyKey = value
  355. End Set
  356. End Property
  357.  
  358. Private _BorderStyle As FormBorderStyle
  359. Property BorderStyle() As FormBorderStyle
  360. Get
  361. If _IsParentForm AndAlso Not _ControlMode Then Return ParentForm.FormBorderStyle Else Return _BorderStyle
  362. End Get
  363. Set(ByVal value As FormBorderStyle)
  364. If _IsParentForm AndAlso Not _ControlMode Then ParentForm.FormBorderStyle = value
  365. _BorderStyle = value
  366. End Set
  367. End Property
  368.  
  369. Private _NoRounding As Boolean
  370. Property NoRounding() As Boolean
  371. Get
  372. Return _NoRounding
  373. End Get
  374. Set(ByVal v As Boolean)
  375. _NoRounding = v
  376. Invalidate()
  377. End Set
  378. End Property
  379.  
  380. Private _Image As Image
  381. Property Image() As Image
  382. Get
  383. Return _Image
  384. End Get
  385. Set(ByVal value As Image)
  386. If value Is Nothing Then
  387. _ImageSize = Size.Empty
  388. Else
  389. _ImageSize = value.Size
  390. End If
  391.  
  392. _Image = value
  393. Invalidate()
  394. End Set
  395. End Property
  396.  
  397. Private _ImageSize As Size
  398. Protected ReadOnly Property ImageSize() As Size
  399. Get
  400. Return _ImageSize
  401. End Get
  402. End Property
  403.  
  404. Private _IsParentForm As Boolean
  405. Protected ReadOnly Property IsParentForm As Boolean
  406. Get
  407. Return _IsParentForm
  408. End Get
  409. End Property
  410.  
  411. Private _LockWidth As Integer
  412. Protected Property LockWidth() As Integer
  413. Get
  414. Return _LockWidth
  415. End Get
  416. Set(ByVal value As Integer)
  417. _LockWidth = value
  418. If Not LockWidth = 0 AndAlso IsHandleCreated Then Width = LockWidth
  419. End Set
  420. End Property
  421.  
  422. Private _LockHeight As Integer
  423. Protected Property LockHeight() As Integer
  424. Get
  425. Return _LockHeight
  426. End Get
  427. Set(ByVal value As Integer)
  428. _LockHeight = value
  429. If Not LockHeight = 0 AndAlso IsHandleCreated Then Height = LockHeight
  430. End Set
  431. End Property
  432.  
  433. Private Items As New Dictionary(Of String, Color)
  434. <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
  435. Property Colors() As Bloom()
  436. Get
  437. Dim T As New List(Of Bloom)
  438. Dim E As Dictionary(Of String, Color).Enumerator = Items.GetEnumerator
  439.  
  440. While E.MoveNext
  441. T.Add(New Bloom(E.Current.Key, E.Current.Value))
  442. End While
  443.  
  444. Return T.ToArray
  445. End Get
  446. Set(ByVal value As Bloom())
  447. For Each B As Bloom In value
  448. If Items.ContainsKey(B.Name) Then Items(B.Name) = B.Value
  449. Next
  450.  
  451. InvalidateCustimization()
  452. ColorHook()
  453. Invalidate()
  454. End Set
  455. End Property
  456.  
  457. Private _Customization As String
  458. Property Customization() As String
  459. Get
  460. Return _Customization
  461. End Get
  462. Set(ByVal value As String)
  463. If value = _Customization Then Return
  464.  
  465. Dim Data As Byte()
  466. Dim Items As Bloom() = Colors
  467.  
  468. Try
  469. Data = Convert.FromBase64String(value)
  470. For I As Integer = 0 To Items.Length - 1
  471. Items(I).Value = Color.FromArgb(BitConverter.ToInt32(Data, I * 4))
  472. Next
  473. Catch
  474. Return
  475. End Try
  476.  
  477. _Customization = value
  478.  
  479. Colors = Items
  480. ColorHook()
  481. Invalidate()
  482. End Set
  483. End Property
  484.  
  485. #End Region
  486.  
  487. #Region " Property Helpers "
  488.  
  489. Protected Function GetColor(ByVal name As String) As Color
  490. Return Items(name)
  491. End Function
  492.  
  493. Protected Sub SetColor(ByVal name As String, ByVal color As Color)
  494. If Items.ContainsKey(name) Then Items(name) = color Else Items.Add(name, color)
  495. End Sub
  496. Protected Sub SetColor(ByVal name As String, ByVal r As Byte, ByVal g As Byte, ByVal b As Byte)
  497. SetColor(name, Color.FromArgb(r, g, b))
  498. End Sub
  499. Protected Sub SetColor(ByVal name As String, ByVal a As Byte, ByVal r As Byte, ByVal g As Byte, ByVal b As Byte)
  500. SetColor(name, Color.FromArgb(a, r, g, b))
  501. End Sub
  502. Protected Sub SetColor(ByVal name As String, ByVal a As Byte, ByVal color As Color)
  503. SetColor(name, color.FromArgb(a, color))
  504. End Sub
  505.  
  506. Private Sub InvalidateCustimization()
  507. Dim M As New MemoryStream(Items.Count * 4)
  508.  
  509. For Each B As Bloom In Colors
  510. M.Write(BitConverter.GetBytes(B.Value.ToArgb), 0, 4)
  511. Next
  512.  
  513. M.Close()
  514. _Customization = Convert.ToBase64String(M.ToArray)
  515. End Sub
  516.  
  517. #End Region
  518.  
  519.  
  520. #Region " User Hooks "
  521.  
  522. Protected MustOverride Sub ColorHook()
  523. Protected MustOverride Sub PaintHook()
  524.  
  525. #End Region
  526.  
  527.  
  528. #Region " Center Overloads "
  529.  
  530. Private CenterReturn As Point
  531.  
  532. Protected Function Center(ByVal r1 As Rectangle, ByVal s1 As Size) As Point
  533. CenterReturn = New Point((r1.Width \ 2 - s1.Width \ 2) + r1.X, (r1.Height \ 2 - s1.Height \ 2) + r1.Y)
  534. Return CenterReturn
  535. End Function
  536. Protected Function Center(ByVal r1 As Rectangle, ByVal r2 As Rectangle) As Point
  537. Return Center(r1, r2.Size)
  538. End Function
  539.  
  540. Protected Function Center(ByVal w1 As Integer, ByVal h1 As Integer, ByVal w2 As Integer, ByVal h2 As Integer) As Point
  541. CenterReturn = New Point(w1 \ 2 - w2 \ 2, h1 \ 2 - h2 \ 2)
  542. Return CenterReturn
  543. End Function
  544.  
  545. Protected Function Center(ByVal s1 As Size, ByVal s2 As Size) As Point
  546. Return Center(s1.Width, s1.Height, s2.Width, s2.Height)
  547. End Function
  548.  
  549. Protected Function Center(ByVal r1 As Rectangle) As Point
  550. Return Center(ClientRectangle.Width, ClientRectangle.Height, r1.Width, r1.Height)
  551. End Function
  552. Protected Function Center(ByVal s1 As Size) As Point
  553. Return Center(Width, Height, s1.Width, s1.Height)
  554. End Function
  555. Protected Function Center(ByVal w1 As Integer, ByVal h1 As Integer) As Point
  556. Return Center(Width, Height, w1, h1)
  557. End Function
  558.  
  559. #End Region
  560.  
  561. #Region " Measure Overloads "
  562.  
  563. Private MeasureBitmap As Bitmap
  564. Private MeasureGraphics As Graphics
  565.  
  566. Protected Function Measure(ByVal text As String) As Size
  567. Return MeasureGraphics.MeasureString(text, Font, Width).ToSize
  568. End Function
  569. Protected Function Measure() As Size
  570. Return MeasureGraphics.MeasureString(Text, Font).ToSize
  571. End Function
  572.  
  573. #End Region
  574.  
  575. #Region " DrawCorners Overloads "
  576.  
  577. 'TODO: Optimize by checking brush color
  578.  
  579. Private DrawCornersBrush As SolidBrush
  580.  
  581. Protected Sub DrawCorners(ByVal c1 As Color)
  582. DrawCorners(c1, 0, 0, Width, Height)
  583. End Sub
  584. Protected Sub DrawCorners(ByVal c1 As Color, ByVal r1 As Rectangle)
  585. DrawCorners(c1, r1.X, r1.Y, r1.Width, r1.Height)
  586. End Sub
  587. Protected Sub DrawCorners(ByVal c1 As Color, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  588. If _NoRounding Then Return
  589.  
  590. DrawCornersBrush = New SolidBrush(c1)
  591. G.FillRectangle(DrawCornersBrush, x, y, 1, 1)
  592. G.FillRectangle(DrawCornersBrush, x + (width - 1), y, 1, 1)
  593. G.FillRectangle(DrawCornersBrush, x, y + (height - 1), 1, 1)
  594. G.FillRectangle(DrawCornersBrush, x + (width - 1), y + (height - 1), 1, 1)
  595. End Sub
  596.  
  597. #End Region
  598.  
  599. #Region " DrawBorders Overloads "
  600.  
  601. 'TODO: Remove triple overload?
  602.  
  603. Protected Sub DrawBorders(ByVal p1 As Pen, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal offset As Integer)
  604. DrawBorders(p1, x + offset, y + offset, width - (offset * 2), height - (offset * 2))
  605. End Sub
  606. Protected Sub DrawBorders(ByVal p1 As Pen, ByVal offset As Integer)
  607. DrawBorders(p1, 0, 0, Width, Height, offset)
  608. End Sub
  609. Protected Sub DrawBorders(ByVal p1 As Pen, ByVal r As Rectangle, ByVal offset As Integer)
  610. DrawBorders(p1, r.X, r.Y, r.Width, r.Height, offset)
  611. End Sub
  612.  
  613. Protected Sub DrawBorders(ByVal p1 As Pen, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  614. G.DrawRectangle(p1, x, y, width - 1, height - 1)
  615. End Sub
  616. Protected Sub DrawBorders(ByVal p1 As Pen)
  617. DrawBorders(p1, 0, 0, Width, Height)
  618. End Sub
  619. Protected Sub DrawBorders(ByVal p1 As Pen, ByVal r As Rectangle)
  620. DrawBorders(p1, r.X, r.Y, r.Width, r.Height)
  621. End Sub
  622.  
  623. #End Region
  624.  
  625. #Region " DrawText Overloads "
  626.  
  627. 'TODO: Remove triple overloads?
  628.  
  629. Private DrawTextPoint As Point
  630. Private DrawTextSize As Size
  631.  
  632. Protected Sub DrawText(ByVal b1 As Brush, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  633. DrawText(b1, Text, a, x, y)
  634. End Sub
  635. Protected Sub DrawText(ByVal b1 As Brush, ByVal p1 As Point)
  636. DrawText(b1, Text, p1.X, p1.Y)
  637. End Sub
  638. Protected Sub DrawText(ByVal b1 As Brush, ByVal x As Integer, ByVal y As Integer)
  639. DrawText(b1, Text, x, y)
  640. End Sub
  641.  
  642. Protected Sub DrawText(ByVal b1 As Brush, ByVal text As String, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  643. If text.Length = 0 Then Return
  644. DrawTextSize = Measure(text)
  645. DrawTextPoint = New Point(Width \ 2 - DrawTextSize.Width \ 2, MoveHeight \ 2 - DrawTextSize.Height \ 2)
  646.  
  647. Select Case a
  648. Case HorizontalAlignment.Left
  649. DrawText(b1, text, x, DrawTextPoint.Y + y)
  650. Case HorizontalAlignment.Center
  651. DrawText(b1, text, DrawTextPoint.X + x, DrawTextPoint.Y + y)
  652. Case HorizontalAlignment.Right
  653. DrawText(b1, text, Width - DrawTextSize.Width - x, DrawTextPoint.Y + y)
  654. End Select
  655. End Sub
  656. Protected Sub DrawText(ByVal b1 As Brush, ByVal text As String, ByVal p1 As Point)
  657. DrawText(b1, text, p1.X, p1.Y)
  658. End Sub
  659. Protected Sub DrawText(ByVal b1 As Brush, ByVal text As String, ByVal x As Integer, ByVal y As Integer)
  660. If text.Length = 0 Then Return
  661. G.DrawString(text, Font, b1, x, y)
  662. End Sub
  663.  
  664. #End Region
  665.  
  666. #Region " DrawImage Overloads "
  667.  
  668. 'TODO: Remove triple overloads?
  669.  
  670. Private DrawImagePoint As Point
  671.  
  672. Protected Sub DrawImage(ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  673. DrawImage(_Image, a, x, y)
  674. End Sub
  675. Protected Sub DrawImage(ByVal p1 As Point)
  676. DrawImage(_Image, p1.X, p1.Y)
  677. End Sub
  678. Protected Sub DrawImage(ByVal x As Integer, ByVal y As Integer)
  679. DrawImage(_Image, x, y)
  680. End Sub
  681.  
  682. Protected Sub DrawImage(ByVal image As Image, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  683. If image Is Nothing Then Return
  684. DrawImagePoint = New Point(Width \ 2 - image.Width \ 2, MoveHeight \ 2 - image.Height \ 2)
  685.  
  686. Select Case a
  687. Case HorizontalAlignment.Left
  688. DrawImage(image, x, DrawImagePoint.Y + y)
  689. Case HorizontalAlignment.Center
  690. DrawImage(image, DrawImagePoint.X + x, DrawImagePoint.Y + y)
  691. Case HorizontalAlignment.Right
  692. DrawImage(image, Width - image.Width - x, DrawImagePoint.Y + y)
  693. End Select
  694. End Sub
  695. Protected Sub DrawImage(ByVal image As Image, ByVal p1 As Point)
  696. DrawImage(image, p1.X, p1.Y)
  697. End Sub
  698. Protected Sub DrawImage(ByVal image As Image, ByVal x As Integer, ByVal y As Integer)
  699. If image Is Nothing Then Return
  700. G.DrawImage(image, x, y, image.Width, image.Height)
  701. End Sub
  702.  
  703. #End Region
  704.  
  705. #Region " DrawGradient Overloads "
  706.  
  707. 'TODO: Remove triple overload?
  708.  
  709. Private DrawGradientBrush As LinearGradientBrush
  710. Private DrawGradientRectangle As Rectangle
  711.  
  712. Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  713. DrawGradient(blend, x, y, width, height, 90S)
  714. End Sub
  715. 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)
  716. DrawGradient(c1, c2, x, y, width, height, 90S)
  717. End Sub
  718.  
  719. Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal angle As Single)
  720. DrawGradientRectangle = New Rectangle(x, y, width, height)
  721. DrawGradient(blend, DrawGradientRectangle, angle)
  722. End Sub
  723. 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)
  724. DrawGradientRectangle = New Rectangle(x, y, width, height)
  725. DrawGradient(c1, c2, DrawGradientRectangle, angle)
  726. End Sub
  727.  
  728. Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal r As Rectangle, ByVal angle As Single)
  729. DrawGradientBrush = New LinearGradientBrush(r, Color.Empty, Color.Empty, angle)
  730. DrawGradientBrush.InterpolationColors = blend
  731. G.FillRectangle(DrawGradientBrush, r)
  732. End Sub
  733. Protected Sub DrawGradient(ByVal c1 As Color, ByVal c2 As Color, ByVal r As Rectangle, ByVal angle As Single)
  734. DrawGradientBrush = New LinearGradientBrush(r, c1, c2, angle)
  735. G.FillRectangle(DrawGradientBrush, r)
  736. End Sub
  737.  
  738. #End Region
  739.  
  740. End Class
  741.  
  742. MustInherit Class ThemeControl151
  743. Inherits Control
  744.  
  745. Protected G As Graphics, B As Bitmap
  746.  
  747. Sub New()
  748. SetStyle(DirectCast(139270, ControlStyles), True)
  749.  
  750. _ImageSize = Size.Empty
  751.  
  752. MeasureBitmap = New Bitmap(1, 1)
  753. MeasureGraphics = Graphics.FromImage(MeasureBitmap)
  754.  
  755. Font = New Font("Verdana", 8S)
  756.  
  757. InvalidateCustimization()
  758. End Sub
  759.  
  760. Protected Overrides Sub SetBoundsCore(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal specified As BoundsSpecified)
  761. If Not _LockWidth = 0 Then width = _LockWidth
  762. If Not _LockHeight = 0 Then height = _LockHeight
  763. MyBase.SetBoundsCore(x, y, width, height, specified)
  764. End Sub
  765.  
  766. Protected NotOverridable Overrides Sub OnSizeChanged(ByVal e As EventArgs)
  767. If _Transparent AndAlso Not (Width = 0 OrElse Height = 0) Then
  768. B = New Bitmap(Width, Height)
  769. G = Graphics.FromImage(B)
  770. End If
  771.  
  772. Invalidate()
  773. MyBase.OnSizeChanged(e)
  774. End Sub
  775.  
  776. Protected NotOverridable Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  777. If Width = 0 OrElse Height = 0 Then Return
  778.  
  779. If _Transparent Then
  780. PaintHook()
  781. e.Graphics.DrawImage(B, 0, 0)
  782. Else
  783. G = e.Graphics
  784. PaintHook()
  785. End If
  786. End Sub
  787.  
  788. Protected Overrides Sub OnHandleCreated(ByVal e As EventArgs)
  789. InvalidateCustimization()
  790. ColorHook()
  791.  
  792. If Not _LockWidth = 0 Then Width = _LockWidth
  793. If Not _LockHeight = 0 Then Height = _LockHeight
  794. If Not BackColorWait = Nothing Then BackColor = BackColorWait
  795.  
  796. OnCreation()
  797. MyBase.OnHandleCreated(e)
  798. End Sub
  799.  
  800. Protected Overridable Sub OnCreation()
  801. End Sub
  802.  
  803. #Region " State Handling "
  804.  
  805. Protected Overrides Sub OnMouseEnter(ByVal e As EventArgs)
  806. SetState(MouseState.Over)
  807. MyBase.OnMouseEnter(e)
  808. End Sub
  809.  
  810. Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
  811. SetState(MouseState.Over)
  812. MyBase.OnMouseUp(e)
  813. End Sub
  814.  
  815. Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
  816. If e.Button = Windows.Forms.MouseButtons.Left Then SetState(MouseState.Down)
  817. MyBase.OnMouseDown(e)
  818. End Sub
  819.  
  820. Protected Overrides Sub OnMouseLeave(ByVal e As EventArgs)
  821. SetState(MouseState.None)
  822. MyBase.OnMouseLeave(e)
  823. End Sub
  824.  
  825. Protected Overrides Sub OnEnabledChanged(ByVal e As EventArgs)
  826. If Enabled Then SetState(MouseState.None) Else SetState(MouseState.Block)
  827. MyBase.OnEnabledChanged(e)
  828. End Sub
  829.  
  830. Protected State As MouseState
  831. Private Sub SetState(ByVal current As MouseState)
  832. State = current
  833. Invalidate()
  834. End Sub
  835.  
  836. #End Region
  837.  
  838.  
  839. #Region " Property Overrides "
  840.  
  841. Private BackColorWait As Color
  842. Overrides Property BackColor() As Color
  843. Get
  844. Return MyBase.BackColor
  845. End Get
  846. Set(ByVal value As Color)
  847. If IsHandleCreated Then
  848. MyBase.BackColor = value
  849. Else
  850. BackColorWait = value
  851. End If
  852. End Set
  853. End Property
  854.  
  855. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  856. Overrides Property ForeColor() As Color
  857. Get
  858. Return Color.Empty
  859. End Get
  860. Set(ByVal value As Color)
  861. End Set
  862. End Property
  863. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  864. Overrides Property BackgroundImage() As Image
  865. Get
  866. Return Nothing
  867. End Get
  868. Set(ByVal value As Image)
  869. End Set
  870. End Property
  871. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  872. Overrides Property BackgroundImageLayout() As ImageLayout
  873. Get
  874. Return ImageLayout.None
  875. End Get
  876. Set(ByVal value As ImageLayout)
  877. End Set
  878. End Property
  879.  
  880. Overrides Property Text() As String
  881. Get
  882. Return MyBase.Text
  883. End Get
  884. Set(ByVal value As String)
  885. MyBase.Text = value
  886. Invalidate()
  887. End Set
  888. End Property
  889.  
  890. Overrides Property Font() As Font
  891. Get
  892. Return MyBase.Font
  893. End Get
  894. Set(ByVal value As Font)
  895. MyBase.Font = value
  896. Invalidate()
  897. End Set
  898. End Property
  899.  
  900. #End Region
  901.  
  902. #Region " Properties "
  903.  
  904. Private _NoRounding As Boolean
  905. Property NoRounding() As Boolean
  906. Get
  907. Return _NoRounding
  908. End Get
  909. Set(ByVal v As Boolean)
  910. _NoRounding = v
  911. Invalidate()
  912. End Set
  913. End Property
  914.  
  915. Private _Image As Image
  916. Property Image() As Image
  917. Get
  918. Return _Image
  919. End Get
  920. Set(ByVal value As Image)
  921. If value Is Nothing Then
  922. _ImageSize = Size.Empty
  923. Else
  924. _ImageSize = value.Size
  925. End If
  926.  
  927. _Image = value
  928. Invalidate()
  929. End Set
  930. End Property
  931.  
  932. Private _ImageSize As Size
  933. Protected ReadOnly Property ImageSize() As Size
  934. Get
  935. Return _ImageSize
  936. End Get
  937. End Property
  938.  
  939. Private _LockWidth As Integer
  940. Protected Property LockWidth() As Integer
  941. Get
  942. Return _LockWidth
  943. End Get
  944. Set(ByVal value As Integer)
  945. _LockWidth = value
  946. If Not LockWidth = 0 AndAlso IsHandleCreated Then Width = LockWidth
  947. End Set
  948. End Property
  949.  
  950. Private _LockHeight As Integer
  951. Protected Property LockHeight() As Integer
  952. Get
  953. Return _LockHeight
  954. End Get
  955. Set(ByVal value As Integer)
  956. _LockHeight = value
  957. If Not LockHeight = 0 AndAlso IsHandleCreated Then Height = LockHeight
  958. End Set
  959. End Property
  960.  
  961. Private _Transparent As Boolean
  962. Property Transparent() As Boolean
  963. Get
  964. Return _Transparent
  965. End Get
  966. Set(ByVal value As Boolean)
  967. If Not value AndAlso Not BackColor.A = 255 Then
  968. Throw New Exception("Unable to change value to false while a transparent BackColor is in use.")
  969. End If
  970.  
  971. SetStyle(ControlStyles.Opaque, Not value)
  972. SetStyle(ControlStyles.SupportsTransparentBackColor, value)
  973.  
  974. If value Then InvalidateBitmap() Else B = Nothing
  975.  
  976. _Transparent = value
  977. Invalidate()
  978. End Set
  979. End Property
  980.  
  981. Private Items As New Dictionary(Of String, Color)
  982. <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
  983. Property Colors() As Bloom()
  984. Get
  985. Dim T As New List(Of Bloom)
  986. Dim E As Dictionary(Of String, Color).Enumerator = Items.GetEnumerator
  987.  
  988. While E.MoveNext
  989. T.Add(New Bloom(E.Current.Key, E.Current.Value))
  990. End While
  991.  
  992. Return T.ToArray
  993. End Get
  994. Set(ByVal value As Bloom())
  995. For Each B As Bloom In value
  996. If Items.ContainsKey(B.Name) Then Items(B.Name) = B.Value
  997. Next
  998.  
  999. InvalidateCustimization()
  1000. ColorHook()
  1001. Invalidate()
  1002. End Set
  1003. End Property
  1004.  
  1005. Private _Customization As String
  1006. Property Customization() As String
  1007. Get
  1008. Return _Customization
  1009. End Get
  1010. Set(ByVal value As String)
  1011. If value = _Customization Then Return
  1012.  
  1013. Dim Data As Byte()
  1014. Dim Items As Bloom() = Colors
  1015.  
  1016. Try
  1017. Data = Convert.FromBase64String(value)
  1018. For I As Integer = 0 To Items.Length - 1
  1019. Items(I).Value = Color.FromArgb(BitConverter.ToInt32(Data, I * 4))
  1020. Next
  1021. Catch
  1022. Return
  1023. End Try
  1024.  
  1025. _Customization = value
  1026.  
  1027. Colors = Items
  1028. ColorHook()
  1029. Invalidate()
  1030. End Set
  1031. End Property
  1032.  
  1033. #End Region
  1034.  
  1035. #Region " Property Helpers "
  1036.  
  1037. Private Sub InvalidateBitmap()
  1038. If Width = 0 OrElse Height = 0 Then Return
  1039. B = New Bitmap(Width, Height)
  1040. G = Graphics.FromImage(B)
  1041. End Sub
  1042.  
  1043. Protected Function GetColor(ByVal name As String) As Color
  1044. Return Items(name)
  1045. End Function
  1046.  
  1047. Protected Sub SetColor(ByVal name As String, ByVal color As Color)
  1048. If Items.ContainsKey(name) Then Items(name) = color Else Items.Add(name, color)
  1049. End Sub
  1050. Protected Sub SetColor(ByVal name As String, ByVal r As Byte, ByVal g As Byte, ByVal b As Byte)
  1051. SetColor(name, Color.FromArgb(r, g, b))
  1052. End Sub
  1053. Protected Sub SetColor(ByVal name As String, ByVal a As Byte, ByVal r As Byte, ByVal g As Byte, ByVal b As Byte)
  1054. SetColor(name, Color.FromArgb(a, r, g, b))
  1055. End Sub
  1056. Protected Sub SetColor(ByVal name As String, ByVal a As Byte, ByVal color As Color)
  1057. SetColor(name, color.FromArgb(a, color))
  1058. End Sub
  1059.  
  1060. Private Sub InvalidateCustimization()
  1061. Dim M As New MemoryStream(Items.Count * 4)
  1062.  
  1063. For Each B As Bloom In Colors
  1064. M.Write(BitConverter.GetBytes(B.Value.ToArgb), 0, 4)
  1065. Next
  1066.  
  1067. M.Close()
  1068. _Customization = Convert.ToBase64String(M.ToArray)
  1069. End Sub
  1070.  
  1071. #End Region
  1072.  
  1073.  
  1074. #Region " User Hooks "
  1075.  
  1076. Protected MustOverride Sub ColorHook()
  1077. Protected MustOverride Sub PaintHook()
  1078.  
  1079. #End Region
  1080.  
  1081.  
  1082. #Region " Center Overloads "
  1083.  
  1084. Private CenterReturn As Point
  1085.  
  1086. Protected Function Center(ByVal r1 As Rectangle, ByVal s1 As Size) As Point
  1087. CenterReturn = New Point((r1.Width \ 2 - s1.Width \ 2) + r1.X, (r1.Height \ 2 - s1.Height \ 2) + r1.Y)
  1088. Return CenterReturn
  1089. End Function
  1090. Protected Function Center(ByVal r1 As Rectangle, ByVal r2 As Rectangle) As Point
  1091. Return Center(r1, r2.Size)
  1092. End Function
  1093.  
  1094. Protected Function Center(ByVal w1 As Integer, ByVal h1 As Integer, ByVal w2 As Integer, ByVal h2 As Integer) As Point
  1095. CenterReturn = New Point(w1 \ 2 - w2 \ 2, h1 \ 2 - h2 \ 2)
  1096. Return CenterReturn
  1097. End Function
  1098.  
  1099. Protected Function Center(ByVal s1 As Size, ByVal s2 As Size) As Point
  1100. Return Center(s1.Width, s1.Height, s2.Width, s2.Height)
  1101. End Function
  1102.  
  1103. Protected Function Center(ByVal r1 As Rectangle) As Point
  1104. Return Center(ClientRectangle.Width, ClientRectangle.Height, r1.Width, r1.Height)
  1105. End Function
  1106. Protected Function Center(ByVal s1 As Size) As Point
  1107. Return Center(Width, Height, s1.Width, s1.Height)
  1108. End Function
  1109. Protected Function Center(ByVal w1 As Integer, ByVal h1 As Integer) As Point
  1110. Return Center(Width, Height, w1, h1)
  1111. End Function
  1112.  
  1113. #End Region
  1114.  
  1115. #Region " Measure Overloads "
  1116.  
  1117. Private MeasureBitmap As Bitmap
  1118. Private MeasureGraphics As Graphics
  1119.  
  1120. Protected Function Measure(ByVal text As String) As Size
  1121. Return MeasureGraphics.MeasureString(text, Font, Width).ToSize
  1122. End Function
  1123. Protected Function Measure() As Size
  1124. Return MeasureGraphics.MeasureString(Text, Font, Width).ToSize
  1125. End Function
  1126.  
  1127. #End Region
  1128.  
  1129. #Region " DrawCorners Overloads "
  1130.  
  1131. 'TODO: Optimize by checking brush color
  1132.  
  1133. Private DrawCornersBrush As SolidBrush
  1134.  
  1135. Protected Sub DrawCorners(ByVal c1 As Color)
  1136. DrawCorners(c1, 0, 0, Width, Height)
  1137. End Sub
  1138. Protected Sub DrawCorners(ByVal c1 As Color, ByVal r1 As Rectangle)
  1139. DrawCorners(c1, r1.X, r1.Y, r1.Width, r1.Height)
  1140. End Sub
  1141. Protected Sub DrawCorners(ByVal c1 As Color, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  1142. If _NoRounding Then Return
  1143.  
  1144. If _Transparent Then
  1145. B.SetPixel(x, y, c1)
  1146. B.SetPixel(x + (width - 1), y, c1)
  1147. B.SetPixel(x, y + (height - 1), c1)
  1148. B.SetPixel(x + (width - 1), y + (height - 1), c1)
  1149. Else
  1150. DrawCornersBrush = New SolidBrush(c1)
  1151. G.FillRectangle(DrawCornersBrush, x, y, 1, 1)
  1152. G.FillRectangle(DrawCornersBrush, x + (width - 1), y, 1, 1)
  1153. G.FillRectangle(DrawCornersBrush, x, y + (height - 1), 1, 1)
  1154. G.FillRectangle(DrawCornersBrush, x + (width - 1), y + (height - 1), 1, 1)
  1155. End If
  1156. End Sub
  1157.  
  1158. #End Region
  1159.  
  1160. #Region " DrawBorders Overloads "
  1161.  
  1162. 'TODO: Remove triple overload?
  1163.  
  1164. Protected Sub DrawBorders(ByVal p1 As Pen, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal offset As Integer)
  1165. DrawBorders(p1, x + offset, y + offset, width - (offset * 2), height - (offset * 2))
  1166. End Sub
  1167. Protected Sub DrawBorders(ByVal p1 As Pen, ByVal offset As Integer)
  1168. DrawBorders(p1, 0, 0, Width, Height, offset)
  1169. End Sub
  1170. Protected Sub DrawBorders(ByVal p1 As Pen, ByVal r As Rectangle, ByVal offset As Integer)
  1171. DrawBorders(p1, r.X, r.Y, r.Width, r.Height, offset)
  1172. End Sub
  1173.  
  1174. Protected Sub DrawBorders(ByVal p1 As Pen, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  1175. G.DrawRectangle(p1, x, y, width - 1, height - 1)
  1176. End Sub
  1177. Protected Sub DrawBorders(ByVal p1 As Pen)
  1178. DrawBorders(p1, 0, 0, Width, Height)
  1179. End Sub
  1180. Protected Sub DrawBorders(ByVal p1 As Pen, ByVal r As Rectangle)
  1181. DrawBorders(p1, r.X, r.Y, r.Width, r.Height)
  1182. End Sub
  1183.  
  1184. #End Region
  1185.  
  1186. #Region " DrawText Overloads "
  1187.  
  1188. 'TODO: Remove triple overloads?
  1189.  
  1190. Private DrawTextPoint As Point
  1191. Private DrawTextSize As Size
  1192.  
  1193. Protected Sub DrawText(ByVal b1 As Brush, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  1194. DrawText(b1, Text, a, x, y)
  1195. End Sub
  1196. Protected Sub DrawText(ByVal b1 As Brush, ByVal p1 As Point)
  1197. DrawText(b1, Text, p1.X, p1.Y)
  1198. End Sub
  1199. Protected Sub DrawText(ByVal b1 As Brush, ByVal x As Integer, ByVal y As Integer)
  1200. DrawText(b1, Text, x, y)
  1201. End Sub
  1202.  
  1203. Protected Sub DrawText(ByVal b1 As Brush, ByVal text As String, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  1204. If text.Length = 0 Then Return
  1205. DrawTextSize = Measure(text)
  1206. DrawTextPoint = Center(DrawTextSize)
  1207.  
  1208. Select Case a
  1209. Case HorizontalAlignment.Left
  1210. DrawText(b1, text, x, DrawTextPoint.Y + y)
  1211. Case HorizontalAlignment.Center
  1212. DrawText(b1, text, DrawTextPoint.X + x, DrawTextPoint.Y + y)
  1213. Case HorizontalAlignment.Right
  1214. DrawText(b1, text, Width - DrawTextSize.Width - x, DrawTextPoint.Y + y)
  1215. End Select
  1216. End Sub
  1217. Protected Sub DrawText(ByVal b1 As Brush, ByVal text As String, ByVal p1 As Point)
  1218. DrawText(b1, text, p1.X, p1.Y)
  1219. End Sub
  1220. Protected Sub DrawText(ByVal b1 As Brush, ByVal text As String, ByVal x As Integer, ByVal y As Integer)
  1221. If text.Length = 0 Then Return
  1222. G.DrawString(text, Font, b1, x, y)
  1223. End Sub
  1224.  
  1225. #End Region
  1226.  
  1227. #Region " DrawImage Overloads "
  1228.  
  1229. 'TODO: Remove triple overloads?
  1230.  
  1231. Private DrawImagePoint As Point
  1232.  
  1233. Protected Sub DrawImage(ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  1234. DrawImage(_Image, a, x, y)
  1235. End Sub
  1236. Protected Sub DrawImage(ByVal p1 As Point)
  1237. DrawImage(_Image, p1.X, p1.Y)
  1238. End Sub
  1239. Protected Sub DrawImage(ByVal x As Integer, ByVal y As Integer)
  1240. DrawImage(_Image, x, y)
  1241. End Sub
  1242.  
  1243. Protected Sub DrawImage(ByVal image As Image, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  1244. If image Is Nothing Then Return
  1245. DrawImagePoint = Center(image.Size)
  1246.  
  1247. Select Case a
  1248. Case HorizontalAlignment.Left
  1249. DrawImage(image, x, DrawImagePoint.Y + y)
  1250. Case HorizontalAlignment.Center
  1251. DrawImage(image, DrawImagePoint.X + x, DrawImagePoint.Y + y)
  1252. Case HorizontalAlignment.Right
  1253. DrawImage(image, Width - image.Width - x, DrawImagePoint.Y + y)
  1254. End Select
  1255. End Sub
  1256. Protected Sub DrawImage(ByVal image As Image, ByVal p1 As Point)
  1257. DrawImage(image, p1.X, p1.Y)
  1258. End Sub
  1259. Protected Sub DrawImage(ByVal image As Image, ByVal x As Integer, ByVal y As Integer)
  1260. If image Is Nothing Then Return
  1261. G.DrawImage(image, x, y, image.Width, image.Height)
  1262. End Sub
  1263.  
  1264. #End Region
  1265.  
  1266. #Region " DrawGradient Overloads "
  1267.  
  1268. 'TODO: Remove triple overload?
  1269.  
  1270. Private DrawGradientBrush As LinearGradientBrush
  1271. Private DrawGradientRectangle As Rectangle
  1272.  
  1273. Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  1274. DrawGradient(blend, x, y, width, height, 90S)
  1275. End Sub
  1276. 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)
  1277. DrawGradient(c1, c2, x, y, width, height, 90S)
  1278. End Sub
  1279.  
  1280. Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal angle As Single)
  1281. DrawGradientRectangle = New Rectangle(x, y, width, height)
  1282. DrawGradient(blend, DrawGradientRectangle, angle)
  1283. End Sub
  1284. 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)
  1285. DrawGradientRectangle = New Rectangle(x, y, width, height)
  1286. DrawGradient(c1, c2, DrawGradientRectangle, angle)
  1287. End Sub
  1288.  
  1289. Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal r As Rectangle, ByVal angle As Single)
  1290. DrawGradientBrush = New LinearGradientBrush(r, Color.Empty, Color.Empty, angle)
  1291. DrawGradientBrush.InterpolationColors = blend
  1292. G.FillRectangle(DrawGradientBrush, r)
  1293. End Sub
  1294. Protected Sub DrawGradient(ByVal c1 As Color, ByVal c2 As Color, ByVal r As Rectangle, ByVal angle As Single)
  1295. DrawGradientBrush = New LinearGradientBrush(r, c1, c2, angle)
  1296. G.FillRectangle(DrawGradientBrush, r)
  1297. End Sub
  1298.  
  1299. #End Region
  1300.  
  1301. End Class
  1302.  
  1303. MustInherit Class ThemeContainerControl
  1304. Inherits ContainerControl
  1305.  
  1306. #Region " Initialization "
  1307.  
  1308. Protected G As Graphics, B As Bitmap
  1309. Sub New()
  1310. SetStyle(DirectCast(139270, ControlStyles), True)
  1311. B = New Bitmap(1, 1)
  1312. G = Graphics.FromImage(B)
  1313. End Sub
  1314.  
  1315. Sub AllowTransparent()
  1316. SetStyle(ControlStyles.Opaque, False)
  1317. SetStyle(ControlStyles.SupportsTransparentBackColor, True)
  1318. End Sub
  1319.  
  1320. #End Region
  1321.  
  1322. #Region " Convienence "
  1323.  
  1324. Protected MustOverride Sub PaintHook()
  1325. Protected NotOverridable Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  1326. If Width = 0 OrElse Height = 0 Then Return
  1327. G = e.Graphics
  1328. PaintHook()
  1329. End Sub
  1330.  
  1331. Protected Overrides Sub OnSizeChanged(ByVal e As EventArgs)
  1332. If Not Width = 0 AndAlso Not Height = 0 Then
  1333. B = New Bitmap(Width, Height)
  1334. G = Graphics.FromImage(B)
  1335. Invalidate()
  1336. End If
  1337. MyBase.OnSizeChanged(e)
  1338. End Sub
  1339.  
  1340. Private _NoRounding As Boolean
  1341. Property NoRounding() As Boolean
  1342. Get
  1343. Return _NoRounding
  1344. End Get
  1345. Set(ByVal v As Boolean)
  1346. _NoRounding = v
  1347. Invalidate()
  1348. End Set
  1349. End Property
  1350.  
  1351. Private _Rectangle As Rectangle
  1352. Private _Gradient As LinearGradientBrush
  1353.  
  1354. Protected Sub DrawCorners(ByVal c As Color, ByVal rect As Rectangle)
  1355. If _NoRounding Then Return
  1356. B.SetPixel(rect.X, rect.Y, c)
  1357. B.SetPixel(rect.X + (rect.Width - 1), rect.Y, c)
  1358. B.SetPixel(rect.X, rect.Y + (rect.Height - 1), c)
  1359. B.SetPixel(rect.X + (rect.Width - 1), rect.Y + (rect.Height - 1), c)
  1360. End Sub
  1361.  
  1362. Protected Sub DrawBorders(ByVal p1 As Pen, ByVal p2 As Pen, ByVal rect As Rectangle)
  1363. G.DrawRectangle(p1, rect.X, rect.Y, rect.Width - 1, rect.Height - 1)
  1364. G.DrawRectangle(p2, rect.X + 1, rect.Y + 1, rect.Width - 3, rect.Height - 3)
  1365. End Sub
  1366.  
  1367. 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)
  1368. _Rectangle = New Rectangle(x, y, width, height)
  1369. _Gradient = New LinearGradientBrush(_Rectangle, c1, c2, angle)
  1370. G.FillRectangle(_Gradient, _Rectangle)
  1371. End Sub
  1372. #End Region
  1373.  
  1374. End Class
  1375.  
  1376. Class Classic
  1377. Inherits ThemeContainer151
  1378. Private Bloom As Bloom()
  1379. Private R1 As Rectangle
  1380. Private L1 As LinearGradientBrush
  1381. Private H As HatchBrush
  1382. Sub New()
  1383. Bloom = {New Bloom("Border", Color.Black), New Bloom("Highlight Border", Color.FromArgb(87, 87, 87)), _
  1384. New Bloom("BackColor", Color.FromArgb(51, 51, 51)), New Bloom("Text Color", Color.FromArgb(128, Color.White)), _
  1385. New Bloom("Background", Color.FromArgb(73, 73, 73)), New Bloom("Grid Color", Color.FromArgb(128, 31, 31, 31)), _
  1386. New Bloom("Gradient #1", Color.FromArgb(128, Color.Black)), New Bloom("Highlight", Color.FromArgb(26, Color.White)), _
  1387. New Bloom("Shadow", Color.FromArgb(10, Color.Black)), New Bloom("Trasparency", Color.Fuchsia) With {.Pen = New Pen(.Value, 2)}}
  1388. TransparencyKey = Color.Fuchsia
  1389. MoveHeight = 22
  1390. Font = New Font("Verdana", 7.0F)
  1391. End Sub
  1392. Protected Overrides Sub ColorHook()
  1393.  
  1394. End Sub
  1395.  
  1396. Protected Overrides Sub PaintHook()
  1397. G.Clear(Bloom(0).Value)
  1398. DrawBorders(Bloom(1).Pen, 1, 1, Width - 2, Height - 2)
  1399. G.FillRectangle(Bloom(2).Brush, 2, 2, Width - 4, 18)
  1400. G.FillRectangle(Bloom(2).Brush, 2, Height - 20, Width - 4, 18)
  1401. G.DrawLine(Bloom(1).Pen, 2, 21, Width - 2, 21)
  1402. G.FillRectangle(Bloom(4).Brush, 2, 22, Width - 4, Height - 44)
  1403. G.DrawLine(Bloom(1).Pen, 2, Height - 21, Width - 2, Height - 21)
  1404.  
  1405. H = New HatchBrush(HatchStyle.SmallCheckerBoard, Bloom(5).Value, Color.Transparent)
  1406. R1 = New Rectangle(2, 2, Width - 4, Height)
  1407. L1 = New LinearGradientBrush(R1, Color.Transparent, Bloom(6).Value, 270S)
  1408. G.FillRectangle(L1, ClientRectangle)
  1409.  
  1410. G.FillRectangle(H, 2, 22, Width - 4, Height - 44)
  1411.  
  1412. G.FillRectangle(Bloom(7).Brush, 0, 0, Width, 5)
  1413.  
  1414. G.FillRectangle(Bloom(8).Brush, 0, 4, Width, Height - 10)
  1415.  
  1416. If _Round Then
  1417. G.DrawArc(Bloom(9).Pen, -1, -1, 9, 9, 180, 90)
  1418. G.DrawArc(Bloom(9).Pen, Width - 9, -1, 9, 9, 270, 90)
  1419.  
  1420. G.DrawArc(Bloom(9).Pen, Width - 9, Height - 9, 9, 9, 360, 90)
  1421. G.DrawArc(Bloom(9).Pen, -1, Height - 9, 9, 9, 90, 90)
  1422.  
  1423. G.DrawArc(Bloom(0).Pen, 0, 0, 9, 9, 180, 90)
  1424. G.DrawArc(Bloom(0).Pen, Width - 10, 0, 9, 9, 270, 90)
  1425.  
  1426. G.DrawArc(Bloom(0).Pen, Width - 10, Height - 10, 9, 9, 360, 90)
  1427. G.DrawArc(Bloom(0).Pen, 0, Height - 10, 9, 9, 90, 90)
  1428. Else
  1429. DrawCorners(Color.Fuchsia)
  1430. End If
  1431.  
  1432. DrawText(Bloom(3).Brush, 5, 5)
  1433. End Sub
  1434.  
  1435. Private _Round As Boolean = False
  1436. Public Property NewProperty() As Boolean
  1437. Get
  1438. Return _Round
  1439. End Get
  1440. Set(ByVal value As Boolean)
  1441. _Round = value
  1442. Invalidate()
  1443. End Set
  1444. End Property
  1445.  
  1446. End Class
  1447. Class ClassicButton
  1448. Inherits ThemeControl151
  1449. Private Bloom As Bloom()
  1450. Private L1 As LinearGradientBrush
  1451. Private R1 As Rectangle
  1452. Sub New()
  1453. Bloom = {New Bloom("Border", Color.Black), New Bloom("Highlight", Color.FromArgb(35, 35, 35)), _
  1454. New Bloom("Background", Color.FromArgb(24, 24, 24)), New Bloom("Shadow", Color.FromArgb(100, Color.Black)), _
  1455. New Bloom("Text Color", Color.FromArgb(128, Color.White))}
  1456. Font = New Font("Verdana", 7.0F)
  1457. Size = New Size(97, 23)
  1458. End Sub
  1459.  
  1460. Protected Overrides Sub ColorHook()
  1461.  
  1462. End Sub
  1463.  
  1464. Protected Overrides Sub PaintHook()
  1465. G.FillRectangle(Bloom(2).Brush, ClientRectangle)
  1466. DrawBorders(Bloom(0).Pen, ClientRectangle)
  1467. DrawBorders(Bloom(1).Pen, 1, 1, Width - 2, Height - 2)
  1468. R1 = New Rectangle(2, 2, Width - 4, Height - 4)
  1469. Select Case State
  1470. Case MouseState.Over
  1471. L1 = New LinearGradientBrush(ClientRectangle, Color.FromArgb(100, 0, 156, 255), Color.Transparent, 270S)
  1472. G.FillRectangle(L1, R1)
  1473. G.FillRectangle(Bloom(3).Brush, 1, 7, Width - 2, Height - 7)
  1474. Case MouseState.Down
  1475. L1 = New LinearGradientBrush(ClientRectangle, Color.FromArgb(50, 0, 156, 255), Color.Transparent, 90S)
  1476. G.FillRectangle(L1, R1)
  1477. G.FillRectangle(Bloom(3).Brush, 1, 7, Width - 2, Height - 7)
  1478. Case MouseState.None
  1479. G.FillRectangle(Bloom(3).Brush, 1, 8, Width - 2, Height - 8)
  1480. End Select
  1481. DrawText(Bloom(4).Brush, HorizontalAlignment.Center, 0, 0)
  1482. End Sub
  1483. End Class
  1484. Class ClassicPanel
  1485. Inherits ThemeContainerControl
  1486. Private Bloom As Bloom()
  1487. Private L1, L2, L3 As LinearGradientBrush
  1488. Private R1, R2, R3 As Rectangle
  1489. Sub New()
  1490. Bloom = {New Bloom("Border", Color.FromArgb(87, 87, 87)), New Bloom("Border #2", Color.Black), _
  1491. New Bloom("Color #1", Color.FromArgb(49, 49, 49)), New Bloom("Color #2", Color.FromArgb(35, 35, 35)), _
  1492. New Bloom("Shadow", Color.FromArgb(31, 31, 31))}
  1493. End Sub
  1494.  
  1495. Protected Overrides Sub PaintHook()
  1496. G.Clear(Color.White)
  1497. DrawBorders(Bloom(0).Pen, Bloom(1).Pen, ClientRectangle)
  1498. DrawCorners(BackColor, ClientRectangle)
  1499. R1 = New Rectangle(2, 2, Width - 4, Height - 4)
  1500. R2 = New Rectangle(2, 2, 15, Height - 4)
  1501. R3 = New Rectangle(2, 2, Width - 4, 15)
  1502. L1 = New LinearGradientBrush(R1, Bloom(2).Value, Bloom(3).Value, 90S)
  1503. L2 = New LinearGradientBrush(R2, Bloom(4).Value, Color.Transparent, 0S)
  1504. L3 = New LinearGradientBrush(R3, Bloom(4).Value, Color.Transparent, 90S)
  1505. G.FillRectangle(L1, R1)
  1506. G.FillRectangle(L2, R2)
  1507. G.FillRectangle(L3, R3)
  1508. End Sub
  1509. End Class
Advertisement
Add Comment
Please, Sign In to add comment