Advertisement
benito

Untitled

Sep 7th, 2011
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 13.04 KB | None | 0 0
  1.     Imports System.Drawing.Drawing2D
  2.      
  3.     Class BullionTheme
  4.         Inherits Control
  5.      
  6.         Protected Overrides Sub OnHandleCreated(ByVal e As EventArgs)
  7.             Dock = DockStyle.Fill
  8.             If TypeOf Parent Is Form Then
  9.                 With DirectCast(Parent, Form)
  10.                     .FormBorderStyle = 0
  11.                     .BackColor = C1
  12.                     .ForeColor = Color.FromArgb(170, 170, 170)
  13.                 End With
  14.             End If
  15.             MyBase.OnHandleCreated(e)
  16.         End Sub
  17.         Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
  18.             If New Rectangle(Parent.Location.X, Parent.Location.Y, Width, 22).IntersectsWith(New Rectangle(MousePosition.X, MousePosition.Y, 1, 1)) Then
  19.                 Capture = False
  20.                 Dim M As Message = Message.Create(Parent.Handle, 161, New IntPtr(2), IntPtr.Zero)
  21.                 DefWndProc(M)
  22.             End If
  23.             MyBase.OnMouseDown(e)
  24.         End Sub
  25.      
  26.         Dim G As Graphics, B As Bitmap, R1, R2 As Rectangle
  27.         Dim C1, C2, C3 As Color, P1, P2, P3, P4 As Pen, B1 As SolidBrush, B2, B3 As LinearGradientBrush
  28.      
  29.         Sub New()
  30.      
  31.             SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint, True)
  32.             C1 = Color.FromArgb(248, 248, 248) 'Background
  33.             C2 = Color.FromArgb(255, 255, 255) 'Highlight
  34.             C3 = Color.FromArgb(235, 235, 235) 'Shadow
  35.             P1 = New Pen(Color.FromArgb(215, 215, 215)) 'Border
  36.             P4 = New Pen(Color.FromArgb(230, 230, 230)) 'Diagnol Lines
  37.             P2 = New Pen(C1)
  38.             P3 = New Pen(C2)
  39.             B1 = New SolidBrush(Color.FromArgb(170, 170, 170))
  40.             Font = New Font("Verdana", 7.0F)
  41.      
  42.         End Sub
  43.      
  44.         Protected Overrides Sub OnSizeChanged(ByVal e As EventArgs)
  45.             If Height > 0 Then
  46.                 R1 = New Rectangle(0, 2, Width, 18)
  47.                 R2 = New Rectangle(0, 21, Width, 10)
  48.                 B2 = New LinearGradientBrush(R1, C1, C3, 90.0F)
  49.                 B3 = New LinearGradientBrush(R2, Color.FromArgb(18, 0, 0, 0), Color.Transparent, 90.0F)
  50.                 Invalidate()
  51.             End If
  52.             MyBase.OnSizeChanged(e)
  53.         End Sub
  54.      
  55.         Protected Overrides Sub OnPaintBackground(ByVal pevent As PaintEventArgs)
  56.         End Sub
  57.      
  58.         Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  59.             B = New Bitmap(Width, Height)
  60.             G = Graphics.FromImage(B)
  61.      
  62.             G.Clear(C1)
  63.      
  64.             For I As Integer = 0 To Width + 17 Step 4
  65.                 G.DrawLine(P4, I, 21, I - 17, 37)
  66.                 G.DrawLine(P4, I - 1, 21, I - 16, 37)
  67.             Next
  68.             G.FillRectangle(B3, R2)
  69.      
  70.             G.FillRectangle(B2, R1)
  71.             G.DrawString(Text, Font, B1, 5, 5)
  72.      
  73.             G.DrawRectangle(P2, 1, 1, Width - 3, 19)
  74.             G.DrawRectangle(P3, 1, 39, Width - 3, Height - 41)
  75.      
  76.             G.DrawRectangle(P1, 0, 0, Width - 1, Height - 1)
  77.             G.DrawLine(P1, 0, 21, Width, 21)
  78.             G.DrawLine(P1, 0, 38, Width, 38)
  79.      
  80.             e.Graphics.DrawImage(B, 0, 0)
  81.             G.Dispose()
  82.             B.Dispose()
  83.         End Sub
  84.      
  85.     End Class
  86.     Class BullionButton
  87.         Inherits Control
  88.      
  89.      
  90.         Private _Image As Image, ImageSet As Boolean
  91.         Public Property Image() As Image
  92.             Get
  93.                 Return _Image
  94.             End Get
  95.             Set(ByVal v As Image)
  96.                 _Image = v
  97.                 ImageSet = v IsNot Nothing
  98.             End Set
  99.         End Property
  100.      
  101.      
  102.         Dim B As Bitmap, G As Graphics, R1 As Rectangle
  103.         Dim C1, C2, C3, C4 As Color, P1, P2, P3, P4 As Pen, B1, B2, B5 As Brush, B3, B4 As LinearGradientBrush
  104.      
  105.         Sub New()
  106.             SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint, True)
  107.             C1 = Color.FromArgb(244, 244, 244) 'Background
  108.             C2 = Color.FromArgb(220, 220, 220) 'Highlight
  109.             C3 = Color.FromArgb(248, 248, 248) 'Lesser Highlight
  110.             C4 = Color.FromArgb(24, Color.Black)
  111.             P1 = New Pen(Color.FromArgb(255, 255, 255)) 'Shadow
  112.             P2 = New Pen(Color.FromArgb(40, Color.White))
  113.             P3 = New Pen(Color.FromArgb(20, Color.White))
  114.             P4 = New Pen(Color.FromArgb(10, Color.Black)) 'Down-Left
  115.             B1 = New SolidBrush(C1)
  116.             B2 = New SolidBrush(C3)
  117.             B5 = New SolidBrush(Color.FromArgb(170, 170, 170)) 'Text Color
  118.             Font = New Font("Verdana", 8.0F)
  119.         End Sub
  120.      
  121.         Private State As Integer
  122.         Protected Overrides Sub OnMouseLeave(ByVal e As EventArgs)
  123.             State = 0
  124.             Invalidate()
  125.         End Sub
  126.         Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
  127.             State = 1
  128.             Invalidate()
  129.         End Sub
  130.         Protected Overrides Sub OnMouseEnter(ByVal e As EventArgs)
  131.             State = 1
  132.             Invalidate()
  133.         End Sub
  134.         Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
  135.             State = 2
  136.             Invalidate()
  137.         End Sub
  138.      
  139.         Protected Overrides Sub OnResize(ByVal e As EventArgs)
  140.             R1 = New Rectangle(2, 2, Width - 4, 4)
  141.             B3 = New LinearGradientBrush(ClientRectangle, C3, C2, 90.0F)
  142.             B4 = New LinearGradientBrush(R1, C4, Color.Transparent, 90.0F)
  143.             Invalidate()
  144.         End Sub
  145.      
  146.         Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  147.             B = New Bitmap(Width, Height)
  148.             G = Graphics.FromImage(B)
  149.      
  150.             G.FillRectangle(B3, ClientRectangle)
  151.      
  152.             Select Case State
  153.                 Case 0 'Up
  154.                     G.FillRectangle(B2, 1, 1, Width - 2, Height - 2)
  155.                     G.DrawRectangle(P4, 2, 2, Width - 5, Height - 5)
  156.                 Case 1 'Over
  157.                     G.FillRectangle(B1, 1, 1, Width - 2, Height - 2)
  158.                     G.DrawRectangle(P4, 2, 2, Width - 5, Height - 5)
  159.                 Case 2 'Down
  160.                     G.FillRectangle(B1, 1, 1, Width - 2, Height - 2)
  161.                     G.FillRectangle(B4, R1)
  162.                     G.DrawLine(P4, 2, 2, 2, Height - 3)
  163.             End Select
  164.      
  165.             Dim S As SizeF = G.MeasureString(Text, Font)
  166.             G.DrawString(Text, Font, B5, Convert.ToInt32(Width / 2 - S.Width / 2), Convert.ToInt32(Height / 2 - S.Height / 2))
  167.      
  168.             G.DrawRectangle(P1, 1, 1, Width - 3, Height - 3)
  169.      
  170.             If ImageSet Then G.DrawImage(_Image, 5, CInt(Height / 2 - _Image.Height / 2), _Image.Width, _Image.Height)
  171.      
  172.             e.Graphics.DrawImage(B, 0, 0)
  173.             G.Dispose()
  174.             B.Dispose()
  175.         End Sub
  176.      
  177.         Protected Overrides Sub OnPaintBackground(ByVal e As PaintEventArgs)
  178.         End Sub
  179.      
  180.     End Class
  181.     Class BullionProgressBar
  182.         Inherits Control
  183.      
  184.     #Region " Properties "
  185.         Private _Maximum As Double = 100
  186.         Public Property Maximum() As Double
  187.             Get
  188.                 Return _Maximum
  189.             End Get
  190.             Set(ByVal v As Double)
  191.                 _Maximum = v
  192.                 Progress = _Current / v * 100
  193.                 Invalidate()
  194.             End Set
  195.         End Property
  196.         Private _Current As Double
  197.         Public Property Current() As Double
  198.             Get
  199.                 Return _Current
  200.             End Get
  201.             Set(ByVal v As Double)
  202.                 _Current = v
  203.                 Progress = v / _Maximum * 100
  204.                 Invalidate()
  205.             End Set
  206.         End Property
  207.         Private _Progress As Integer
  208.         Public Property Progress() As Double
  209.             Get
  210.                 Return _Progress
  211.             End Get
  212.             Set(ByVal v As Double)
  213.                 If v < 0 Then v = 0 Else If v > 100 Then v = 100
  214.                 _Progress = Convert.ToInt32(v)
  215.                 _Current = v * 0.01 * _Maximum
  216.                 If Width > 0 Then UpdateProgress()
  217.                 Invalidate()
  218.             End Set
  219.         End Property
  220.      
  221.         Dim C2 As Color = Color.PaleTurquoise  'Dark Color
  222.         Public Property Color1() As Color
  223.             Get
  224.                 Return C2
  225.             End Get
  226.             Set(ByVal v As Color)
  227.                 C2 = v
  228.                 UpdateColors()
  229.                 Invalidate()
  230.             End Set
  231.         End Property
  232.         Dim C3 As Color = Color.AliceBlue  'Light color
  233.         Public Property Color2() As Color
  234.             Get
  235.                 Return C3
  236.             End Get
  237.             Set(ByVal v As Color)
  238.                 C3 = v
  239.                 UpdateColors()
  240.                 Invalidate()
  241.             End Set
  242.         End Property
  243.      
  244.     #End Region
  245.      
  246.         Protected Overrides Sub OnPaintBackground(ByVal pevent As PaintEventArgs)
  247.         End Sub
  248.      
  249.         Dim G As Graphics, B As Bitmap, R1, R2 As Rectangle, X As ColorBlend
  250.         Dim C1 As Color, P1, P2, P3 As Pen, B1, B2 As LinearGradientBrush, B3 As SolidBrush
  251.         Sub New()
  252.      
  253.             C1 = Color.FromArgb(246, 246, 246) 'Background
  254.             P1 = New Pen(Color.FromArgb(70, Color.White), 2)
  255.             P2 = New Pen(C2)
  256.             P3 = New Pen(Color.FromArgb(255, 255, 255)) 'Highlight
  257.             B3 = New SolidBrush(Color.FromArgb(100, Color.White))
  258.             X = New ColorBlend(4)
  259.             X.Colors = {C2, C3, C3, C2}
  260.             X.Positions = {0.0F, 0.1F, 0.9F, 1.0F}
  261.             R2 = New Rectangle(2, 2, 2, 2)
  262.             B2 = New LinearGradientBrush(R2, Nothing, Nothing, 180.0F)
  263.             B2.InterpolationColors = X
  264.      
  265.         End Sub
  266.      
  267.         Sub UpdateColors()
  268.             P2.Color = C2
  269.             X.Colors = {C2, C3, C3, C2}
  270.             B2.InterpolationColors = X
  271.         End Sub
  272.      
  273.         Protected Overrides Sub OnSizeChanged(ByVal e As System.EventArgs)
  274.             R1 = New Rectangle(0, 1, Width, 4)
  275.             B1 = New LinearGradientBrush(R1, Color.FromArgb(24, Color.Black), Color.Transparent, 90.0F)
  276.             UpdateProgress()
  277.             Invalidate()
  278.             MyBase.OnSizeChanged(e)
  279.         End Sub
  280.      
  281.         Sub UpdateProgress()
  282.             If _Progress = 0 Then Return
  283.             R2 = New Rectangle(2, 2, Convert.ToInt32((Width - 4) * (_Progress * 0.01)), Height - 4)
  284.             B2 = New LinearGradientBrush(R2, Nothing, Nothing, 180.0F)
  285.             B2.InterpolationColors = X
  286.         End Sub
  287.      
  288.         Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  289.             B = New Bitmap(Width, Height)
  290.             G = Graphics.FromImage(B)
  291.      
  292.             G.Clear(C1)
  293.      
  294.             G.FillRectangle(B1, R1)
  295.      
  296.             If _Progress > 0 Then
  297.                 G.FillRectangle(B2, R2)
  298.      
  299.                 G.FillRectangle(B3, 2, 3, R2.Width, 4)
  300.                 G.DrawRectangle(P1, 4, 4, R2.Width - 4, Height - 8)
  301.      
  302.                 G.DrawRectangle(P2, 2, 2, R2.Width - 1, Height - 5)
  303.             End If
  304.      
  305.             G.DrawRectangle(P3, 0, 0, Width - 1, Height - 1)
  306.      
  307.             e.Graphics.DrawImage(B, 0, 0)
  308.             G.Dispose()
  309.             B.Dispose()
  310.         End Sub
  311.      
  312.     End Class
  313.     Class BullionSeperator
  314.         Inherits Control
  315.      
  316.         Private _Orientation As Orientation
  317.         Public Property Orientation() As Orientation
  318.             Get
  319.                 Return _Orientation
  320.             End Get
  321.             Set(ByVal v As Orientation)
  322.                 _Orientation = v
  323.                 UpdateOffset()
  324.                 Invalidate()
  325.             End Set
  326.         End Property
  327.      
  328.         Dim G As Graphics, B As Bitmap, I As Integer
  329.         Dim C1 As Color, P1, P2 As Pen
  330.         Sub New()
  331.             SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint, True)
  332.             C1 = Color.FromArgb(248, 248, 248) 'Background
  333.             P1 = New Pen(Color.FromArgb(230, 230, 230)) 'Shadow
  334.             P2 = New Pen(Color.FromArgb(255, 255, 255)) 'Highlight
  335.         End Sub
  336.      
  337.         Protected Overrides Sub OnSizeChanged(ByVal e As EventArgs)
  338.             UpdateOffset()
  339.             MyBase.OnSizeChanged(e)
  340.         End Sub
  341.      
  342.         Sub UpdateOffset()
  343.             I = Convert.ToInt32(If(_Orientation = 0, Height / 2 - 1, Width / 2 - 1))
  344.         End Sub
  345.      
  346.         Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  347.             B = New Bitmap(Width, Height)
  348.             G = Graphics.FromImage(B)
  349.      
  350.             G.Clear(C1)
  351.      
  352.             If _Orientation = 0 Then
  353.                 G.DrawLine(P1, 0, I, Width, I)
  354.                 G.DrawLine(P2, 0, I + 1, Width, I + 1)
  355.             Else
  356.                 G.DrawLine(P2, I, 0, I, Height)
  357.                 G.DrawLine(P1, I + 1, 0, I + 1, Height)
  358.             End If
  359.      
  360.             e.Graphics.DrawImage(B, 0, 0)
  361.             G.Dispose()
  362.             B.Dispose()
  363.         End Sub
  364.      
  365.         Protected Overrides Sub OnPaintBackground(ByVal pevent As PaintEventArgs)
  366.         End Sub
  367.      
  368.     End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement