home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / status_1 / statusba.ctl < prev    next >
Encoding:
Text File  |  1999-07-15  |  11.3 KB  |  411 lines

  1. VERSION 5.00
  2. Begin VB.UserControl StatusBar 
  3.    Appearance      =   0  'Flat
  4.    AutoRedraw      =   -1  'True
  5.    BorderStyle     =   1  'Fixed Single
  6.    CanGetFocus     =   0   'False
  7.    ClientHeight    =   390
  8.    ClientLeft      =   0
  9.    ClientTop       =   0
  10.    ClientWidth     =   1965
  11.    ClipControls    =   0   'False
  12.    ScaleHeight     =   26
  13.    ScaleMode       =   3  'Pixel
  14.    ScaleWidth      =   131
  15.    ToolboxBitmap   =   "StatusBar.ctx":0000
  16. End
  17. Attribute VB_Name = "StatusBar"
  18. Attribute VB_GlobalNameSpace = False
  19. Attribute VB_Creatable = True
  20. Attribute VB_PredeclaredId = False
  21. Attribute VB_Exposed = True
  22. Option Explicit
  23.  
  24. Const GRAY = &HC0C0C0
  25.  
  26. Enum BackStyleOpt
  27.     Opaque = 0
  28.     Transparent = 1
  29. End Enum
  30.  
  31. Enum BorderStyleOpt
  32.     None = 0
  33.     Fixed = 1
  34. End Enum
  35.  
  36. Enum Direction
  37.     Horizontal = 0
  38.     Vertical = 1
  39. End Enum
  40.  
  41. Enum ABoolean
  42.     No
  43.     Yes
  44. End Enum
  45.  
  46. Enum Widths
  47.     Thin = 1
  48.     Thick = 3
  49. End Enum
  50.  
  51. Dim DispSpace As Integer
  52. Dim DispLen As Long
  53. Dim DispVisible As Boolean
  54. Dim DispFillColor As Long
  55. Dim DispBorderColor As Long
  56. Dim DispSweep As Direction
  57. Dim DispBorderStyle As BorderStyleOpt
  58. Dim DispBackStyle As BackStyleOpt
  59. Dim DispBorderWidth As Widths
  60.  
  61. Dim ShwGraph As Boolean
  62. Dim GphColor As Long
  63. Dim GphSpace As Integer
  64. Dim GphLnWidth As Widths
  65. Dim GphLnStyle As BorderStyleConstants
  66.  
  67. Dim DispX1 As Double
  68. Dim DispX2 As Double
  69. Dim DispY1 As Double
  70. Dim DispY2 As Double
  71.  
  72. Dim Max As Double
  73. Dim Min As Double
  74. Dim Val As Double
  75. Dim Perc As Double
  76.  
  77. Event Click()
  78. Event DblClick()
  79. Event MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  80. Event MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  81.  
  82. Property Get GraphLineStyle() As BorderStyleConstants
  83.     GraphLineStyle = GphLnStyle
  84. End Property
  85.  
  86. Property Let GraphLineStyle(NewStyle As BorderStyleConstants)
  87.     GphLnStyle = NewStyle
  88.     PropertyChanged "GraphLineStyle"
  89. End Property
  90.  
  91. Property Get DisplayBorderWidth() As Widths
  92.     DisplayBorderWidth = DispBorderWidth
  93. End Property
  94.  
  95. Property Let DisplayBorderWidth(NewWidth As Widths)
  96.     DispBorderWidth = NewWidth
  97.     PropertyChanged "DisplayBorderWidth"
  98.     PaintDisplay
  99. End Property
  100.  
  101. Property Get GraphLineWidth() As Widths
  102.     GraphLineWidth = GphLnWidth
  103. End Property
  104.  
  105. Property Let GraphLineWidth(NewWidth As Widths)
  106.     GphLnWidth = NewWidth
  107.     PropertyChanged "GraphLineWidth"
  108.     If ShwGraph Then PaintDisplay
  109. End Property
  110.  
  111. Property Get GraphSpacing() As Integer
  112.     GraphSpacing = GphSpace
  113. End Property
  114.  
  115. Property Let GraphSpacing(NewValue As Integer)
  116.     GphSpace = NewValue
  117.     PropertyChanged "GraphSpacing"
  118.     PaintDisplay
  119. End Property
  120.  
  121. Property Get GraphColor() As OLE_COLOR
  122.     GraphColor = GphColor
  123. End Property
  124.  
  125. Property Let GraphColor(NewColor As OLE_COLOR)
  126.     GphColor = NewColor
  127.     PropertyChanged "GraphColor"
  128.     PaintDisplay
  129. End Property
  130.  
  131. Property Get ShowGraph() As Boolean
  132.     ShowGraph = ShwGraph
  133. End Property
  134.  
  135. Property Let ShowGraph(NewSetting As Boolean)
  136.     ShwGraph = NewSetting
  137.     PropertyChanged "ShowGraph"
  138.     If ShwGraph = False Then UserControl_Resize
  139.     If ShwGraph = True Then PaintGraph
  140. End Property
  141.  
  142. Property Get DisplaySpace() As Integer
  143.     DisplaySpace = DispSpace
  144. End Property
  145.  
  146. Property Let DisplaySpace(NewValue As Integer)
  147.     DispSpace = NewValue
  148.     PropertyChanged "DisplaySpace"
  149.     UserControl_Resize
  150. End Property
  151.  
  152. Property Get Percent() As Double
  153.     Percent = Perc
  154. End Property
  155.  
  156. Property Let Percent(NewPercent As Double)
  157.     If NewPercent > 100 Or NewPercent < 0 Then Exit Property
  158.     Perc = NewPercent
  159.     PropertyChanged "Percent"
  160.     Val = Perc / 100 * (Max - Min)
  161.     UserControl_Resize
  162. End Property
  163.  
  164. Property Get Value() As Double
  165.     Value = Val
  166. End Property
  167.  
  168. Property Let Value(NewValue As Double)
  169.     Val = NewValue
  170.     PropertyChanged "Value"
  171.     If Val > Max Then Val = Max
  172.     If Val < Min Then Val = Min
  173.     UserControl_Resize
  174. End Property
  175.  
  176. Property Get Maximum() As Double
  177.     Maximum = Max
  178. End Property
  179.  
  180. Property Let Maximum(NewValue As Double)
  181.     Max = NewValue
  182.     PropertyChanged "Maximum"
  183.     If Val > Max Then Val = Max
  184.     UserControl_Resize
  185. End Property
  186.  
  187. Property Get Minimum() As Double
  188.     Minimum = Min
  189. End Property
  190.  
  191. Property Let Minimum(NewValue As Double)
  192.     Min = NewValue
  193.     PropertyChanged "Minimum"
  194.     If Val < Min Then Val = Min
  195.     UserControl_Resize
  196. End Property
  197.  
  198. Property Get BorderStyle() As BorderStyleOpt
  199.     BorderStyle = UserControl.BorderStyle
  200. End Property
  201.  
  202. Property Let BorderStyle(NewStyle As BorderStyleOpt)
  203.     UserControl.BorderStyle = NewStyle
  204.     PropertyChanged "BorderStyle"
  205. End Property
  206.  
  207. Property Get DisplayBackStyle() As BackStyleOpt
  208.     DisplayBackStyle = DispBackStyle
  209. End Property
  210.  
  211. Property Let DisplayBackStyle(NewStyle As BackStyleOpt)
  212.     DispBackStyle = NewStyle
  213.     PropertyChanged "DisplayBackStyle"
  214.     PaintDisplay
  215. End Property
  216.  
  217. Property Get DisplaySweep() As Direction
  218.     DisplaySweep = DispSweep
  219. End Property
  220.  
  221. Property Let DisplaySweep(NewDirection As Direction)
  222.     DispSweep = NewDirection
  223.     PropertyChanged "DisplaySweep"
  224.     UserControl_Resize
  225. End Property
  226.  
  227. Property Get BackColor() As OLE_COLOR
  228.     BackColor = UserControl.BackColor
  229. End Property
  230.  
  231. Property Let BackColor(NewColor As OLE_COLOR)
  232.     UserControl.BackColor = NewColor
  233.     PropertyChanged "BackColor"
  234. End Property
  235.  
  236. Property Get BorderColor() As OLE_COLOR
  237.     BorderColor = DispBorderColor
  238. End Property
  239.  
  240. Property Let BorderColor(NewColor As OLE_COLOR)
  241.     DispBorderColor = NewColor
  242.     PropertyChanged "BorderColor"
  243.     PaintDisplay
  244. End Property
  245.  
  246. Property Get FillColor() As OLE_COLOR
  247.     FillColor = DispFillColor
  248. End Property
  249.  
  250. Property Let FillColor(NewColor As OLE_COLOR)
  251.     DispFillColor = NewColor
  252.     PropertyChanged "FillColor"
  253.     PaintDisplay
  254. End Property
  255.  
  256. Property Get DisplayBorderStyle() As BorderStyleOpt
  257.     DisplayBorderStyle = DispBorderStyle
  258. End Property
  259.  
  260. Property Let DisplayBorderStyle(NewValue As BorderStyleOpt)
  261.     DispBorderStyle = NewValue
  262.     PropertyChanged "DisplayBorderStyle"
  263.     PaintDisplay
  264. End Property
  265.  
  266. Private Sub UserControl_Click()
  267.     RaiseEvent Click
  268. End Sub
  269.  
  270. Private Sub UserControl_DblClick()
  271.     RaiseEvent DblClick
  272. End Sub
  273.  
  274. Private Sub UserControl_InitProperties()
  275.     DispFillColor = vbGreen
  276.     DispBorderStyle = 1
  277.     UserControl.BorderStyle = 1
  278.     UserControl.BackColor = vbRed
  279.     DispSpace = 2
  280.     Max = 10000
  281.     GphSpace = 5
  282.     GphColor = GRAY
  283.     ShwGraph = False
  284.     GphLnWidth = Thin
  285.     DispBorderWidth = Thin
  286. End Sub
  287.  
  288. Private Sub UserControl_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  289.     RaiseEvent MouseDown(Button, Shift, ScaleX(X, ScaleMode, vbContainerPosition), ScaleY(Y, ScaleMode, vbContainerPosition))
  290. End Sub
  291.  
  292. Private Sub UserControl_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  293.     RaiseEvent MouseMove(Button, Shift, ScaleX(X, ScaleMode, vbContainerPosition), ScaleY(Y, ScaleMode, vbContainerPosition))
  294. End Sub
  295.  
  296. Private Sub UserControl_Paint()
  297.     PaintDisplay
  298. End Sub
  299.  
  300. Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
  301.     DispSpace = PropBag.ReadProperty("DisplaySpace", 2)
  302.     Max = PropBag.ReadProperty("Maximum", 10000)
  303.     Min = PropBag.ReadProperty("Minimum", 0)
  304.     Val = PropBag.ReadProperty("Value", 0)
  305.     DispBorderColor = PropBag.ReadProperty("BorderColor", 0)
  306.     DispFillColor = PropBag.ReadProperty("FillColor", vbGreen)
  307.     DispBackStyle = PropBag.ReadProperty("DisplayBackStyle", 0)
  308.     DispBorderStyle = PropBag.ReadProperty("DisplayBorderStyle", 1)
  309.     DispSweep = PropBag.ReadProperty("DisplaySweep", 0)
  310.     UserControl.BackColor = PropBag.ReadProperty("BackColor", vbRed)
  311.     UserControl.BorderStyle = PropBag.ReadProperty("BorderStyle", 1)
  312.     DispBorderWidth = PropBag.ReadProperty("DisplayBorderWidth", 1)
  313.     GphLnWidth = PropBag.ReadProperty("GraphLineWidth", 1)
  314.     GphLnStyle = PropBag.ReadProperty("GraphLineStyle", 0)
  315.     GphSpace = PropBag.ReadProperty("GraphSpacing", 5)
  316.     GphColor = PropBag.ReadProperty("GraphColor", GRAY)
  317.     ShwGraph = PropBag.ReadProperty("ShowGraph", False)
  318. End Sub
  319.  
  320. Private Sub UserControl_Resize()
  321. Dim SWidth As Double, SHeight As Double
  322.     Cls
  323.     GetPercent
  324.     SWidth = UserControl.ScaleWidth
  325.     SHeight = UserControl.ScaleHeight
  326.     ExchangeData SWidth, SHeight
  327.     DispX1 = DispSpace
  328.     DispY1 = DispSpace
  329.     DispLen = SWidth - DispSpace * 2 - 1
  330.     DispX2 = (Perc / 100) * DispLen + DispX1
  331.     DispY2 = SHeight - DispY1 - 1
  332.     ExchangeData DispX1, DispY1
  333.     ExchangeData DispX2, DispY2
  334.     PaintDisplay
  335. End Sub
  336.  
  337. Private Sub ExchangeData(ByRef Data1 As Variant, ByRef Data2 As Variant)
  338. Dim TempData As Variant
  339.     If DispSweep = Vertical Then
  340.         TempData = Data1
  341.         Data1 = Data2
  342.         Data2 = TempData
  343.     End If
  344. End Sub
  345.  
  346. Private Sub PaintDisplay()
  347.     Cls
  348.     If Percent = 0 Then Exit Sub
  349.     If DispBackStyle = Opaque Then
  350.         UserControl.Line (DispX1, DispY1)-(DispX2, DispY2), DispFillColor, BF
  351.     End If
  352.     If ShwGraph Then PaintGraph
  353.     UserControl.DrawStyle = 0
  354.     If DispBorderWidth = 0 Then DispBorderWidth = Thin
  355.     UserControl.DrawWidth = DispBorderWidth
  356.     If DispBorderStyle = Fixed Then
  357.         UserControl.Line (DispX1, DispY1)-(DispX2, DispY2), DispBorderColor, B
  358.     End If
  359.     DoEvents
  360. End Sub
  361.  
  362. Private Sub GetPercent()
  363.     If Max - Min = 0 Then
  364.         Perc = 0
  365.         Exit Sub
  366.     End If
  367.     Perc = (Val - Min) / (Max - Min) * 100
  368. End Sub
  369.  
  370. Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
  371.     PropBag.WriteProperty "DisplaySpace", DispSpace, 2
  372.     PropBag.WriteProperty "Maximum", Max, 10000
  373.     PropBag.WriteProperty "Minimum", Min, 0
  374.     PropBag.WriteProperty "Value", Val, 0
  375.     PropBag.WriteProperty "BorderColor", DispBorderColor, 0
  376.     PropBag.WriteProperty "FillColor", DispFillColor, vbGreen
  377.     PropBag.WriteProperty "DisplayBackStyle", DispBackStyle, 0
  378.     PropBag.WriteProperty "DisplayBorderStyle", DispBorderStyle, 1
  379.     PropBag.WriteProperty "DisplaySweep", DispSweep, 0
  380.     PropBag.WriteProperty "BackColor", UserControl.BackColor, vbRed
  381.     PropBag.WriteProperty "BorderStyle", UserControl.BorderStyle, 1
  382.     PropBag.WriteProperty "DisplayBorderWidth", DispBorderWidth, 1
  383.     PropBag.WriteProperty "GraphLineWidth", GphLnWidth, 1
  384.     PropBag.WriteProperty "GraphLineStyle", GphLnStyle, 0
  385.     PropBag.WriteProperty "GraphSpacing", GphSpace, 5
  386.     PropBag.WriteProperty "GraphColor", GphColor, GRAY
  387.     PropBag.WriteProperty "ShowGraph", ShwGraph, False
  388. End Sub
  389.  
  390. Private Sub PaintGraph()
  391. Dim i As Integer
  392. Dim LineLeft As Double, LineRight As Double
  393. Dim LineTop As Double, LineBottom As Double
  394.     If GphLnWidth = 0 Then GphLnWidth = Thin
  395.     UserControl.DrawWidth = GphLnWidth
  396.     UserControl.DrawStyle = GphLnStyle
  397.     For i = 0 To Perc \ GphSpace
  398.         LineLeft = DispLen * (i * GphSpace) / 100 + DispSpace
  399.         LineRight = LineLeft
  400.         LineTop = DispY1 + 1
  401.         LineBottom = DispY2
  402.         If DispSweep = Vertical Then
  403.             ExchangeData LineLeft, LineTop
  404.             ExchangeData LineRight, LineBottom
  405.             LineLeft = DispX1 + 1
  406.             LineRight = DispX2
  407.         End If
  408.         Line (LineLeft, LineTop)-(LineRight, LineBottom), GphColor
  409.     Next i
  410. End Sub
  411.