VB进度条 游戏血条控件

 
  1. 在VB中直接添加一个用户控件,将以下代码COPY粘贴进去
  2.   
  3.   
  4. Option Explicit
  5.   
  6. Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As LongByVal X As LongByVal Y As LongByVal nWidth As LongByVal nHeight As LongByVal hSrcDC As LongByVal xSrc As LongByVal ySrc As LongByVal dwRop As LongAs Long
  7. Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As LongByVal hSrcRgn1 As LongByVal hSrcRgn2 As LongByVal nCombineMode As LongAs Long
  8. Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal HDC As LongByVal nWidth As LongByVal nHeight As LongAs Long
  9. Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal HDC As LongAs Long
  10. Private Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" (ByVal lpDriverName As StringByVal lpDeviceName As StringByVal lpOutput As String, lpInitData As Any) As Long
  11. Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As LongByVal Y1 As LongByVal X2 As LongByVal Y2 As LongAs Long
  12. Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As LongAs Long
  13. Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As LongAs Long
  14. Private Declare Function DeleteDC Lib "gdi32" (ByVal HDC As LongAs Long
  15. Private Declare Function DrawText Lib "user32" Alias "DrawTextA" (ByVal HDC As LongByVal lpStr As StringByVal nCount As Long, lpRect As RECT, ByVal wFormat As LongAs Long
  16. Private Declare Function FillRect Lib "user32" (ByVal HDC As Long, lpRect As RECT, ByVal hBrush As LongAs Long
  17. Private Declare Function FrameRect Lib "user32" (ByVal HDC As Long, lpRect As RECT, ByVal hBrush As LongAs Long
  18. Private Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
  19. Private Declare Function GetSysColor Lib "user32" (ByVal nIndex As LongAs Long
  20. Private Declare Function GradientFillRect Lib "msimg32" Alias "GradientFill" (ByVal HDC As Long, pVertex As TRIVERTEX, ByVal dwNumVertex As Long, pMesh As GRADIENT_RECT, ByVal dwNumMesh As LongByVal dwMode As LongAs Long
  21. Private Declare Function SelectObject Lib "gdi32" (ByVal HDC As LongByVal hObject As LongAs Long
  22. Private Declare Function SetBkColor Lib "gdi32" (ByVal HDC As LongByVal crColor As LongAs Long
  23. Private Declare Function SetBkMode Lib "gdi32" (ByVal HDC As LongByVal nBkMode As LongAs Long
  24. Private Declare Function SetPixelV Lib "gdi32" (ByVal HDC As LongByVal X As LongByVal Y As LongByVal crColor As LongAs Long
  25. Private Declare Function SetTextColor Lib "gdi32" (ByVal HDC As LongByVal crColor As LongAs Long
  26. Private Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As LongByVal hRgn As LongByVal bRedraw As LongAs Long
  27.   
  28.   
  29. Const RGN_DIFF     As Long = 4
  30. Const DT_SINGLELINE   As Long = 
  31. Private Type RECT
  32.   Left     As Long
  33.   Top     As Long
  34.   Right   As Long
  35.   Bottom   As Long
  36. End Type
  37. Private Type TRIVERTEX
  38.   X       As Long
  39.   Y       As Long
  40.   Red     As Integer
  41.   Green   As Integer
  42.   Blue     As Integer
  43.   Alpha   As Integer
  44. End Type
  45. Private Type GRADIENT_RECT
  46.   UPPERLEFT As Long
  47.   LOWERRIGHT As Long
  48. End Type
  49. Private Type RGB
  50.   R       As Integer
  51.   G       As Integer
  52.   B       As Integer
  53. End Type
  54. Public Enum cScrolling
  55.   ccScrollingStandard = 0
  56.   ccScrollingSmooth = 1
  57.   ccScrollingSearch = 2
  58. End Enum
  59.   
  60. Public Enum cOrientation
  61.   ccOrientationHorizontal = 0
  62.   ccOrientationVertical = 1
  63. End Enum
  64.   
  65. Private m_Scrolling   As cScrolling
  66. Private m_Orientation As cOrientation
  67.   
  68. Private m_Color     As OLE_COLOR
  69. Private m_hDC     As Long
  70. Private m_hWnd     As Long
  71. Private m_Max     As Long
  72. Private m_Min     As Long
  73. Private m_Value     As Long
  74. Private m_ShowText   As Boolean
  75. Private m_ShowInTask As Boolean
  76.   
  77.   
  78. Private m_MemDC   As Boolean
  79. Private m_ThDC   As Long
  80. Private m_hBmp   As Long
  81. Private m_hBmpOld As Long
  82. Private iFnt     As IFont
  83. Private m_fnt     As IFont
  84. Private hFntOld   As Long
  85. Private m_lWidth   As Long
  86. Private m_lHeight As Long
  87. Private fPercent   As Double
  88. Private TR       As RECT
  89. Private TBR     As RECT
  90. Private TSR     As RECT
  91. Private lSegmentWidth   As Long
  92. Private lSegmentSpacing As Long
  93. Public Sub DrawProgressBar()
  94.   
  95.   GetClientRect m_hWnd, TR
  96.   
  97.   
  98.   DrawFillRectangle TR, vbWhite, m_hDC
  99.   
  100.   CalcBarSize
  101.   
  102.   PBarDraw
  103.   
  104.   If m_Scrolling = 0 Then DrawDivisions
  105.   
  106.   DrawTexto
  107.   
  108.   pDrawBorder
  109.   
  110.   If m_MemDC Then
  111.     With UserControl
  112.         pDraw .HDC, 0, 0, .ScaleWidth, .ScaleHeight, .ScaleLeft, .ScaleTop
  113.     End With
  114.   End If
  115.   
  116. End Sub
  117. Private Sub CalcBarSize()
  118.   
  119.   lSegmentWidth = 8
  120.   lSegmentSpacing = 2
  121.   
  122.   LSet TBR = TR
  123.   
  124.   fPercent = (m_Value - m_Min) / (m_Max - m_Min)
  125.   If fPercent > 1# Then fPercent = 1#
  126.   If fPercent < 0# Then fPercent = 0#
  127.   
  128.   If m_Orientation = 0 Then
  129.     TBR.Right = TR.Left + (TR.Right - TR.Left) * fPercent
  130.     TBR.Right = TBR.Right - ((TBR.Right - TBR.Left) Mod (lSegmentWidth + lSegmentSpacing))
  131.     If TBR.Right < TR.Left Then
  132.         TBR.Right = TR.Left
  133.     End If
  134.     If TBR.Right < TR.Left Then TBR.Right = TR.Left
  135.     
  136.   Else
  137.           fPercent = 1# - fPercent - 0.02
  138.     TBR.Top = TR.Top + (TR.Bottom - TR.Top) * fPercent
  139.     TBR.Top = TBR.Top - ((TBR.Top - TBR.Bottom) Mod (lSegmentWidth + lSegmentSpacing))
  140.     If TBR.Top > TR.Bottom Then TBR.Top = TR.Bottom
  141.     
  142.     
  143.     
  144.   End If
  145.   
  146. End Sub
  147. Private Sub DrawDivisions()
  148.   Dim i As Long
  149.   Dim hBR As Long
  150.   
  151.   hBR = CreateSolidBrush(vbWhite)
  152.   
  153.   LSet TSR = TR
  154.   
  155.   If m_Orientation = 0 Then
  156.     
  157.     For i = TBR.Left + lSegmentWidth To TBR.Right Step lSegmentWidth + lSegmentSpacing
  158.         TSR.Left = i + 2
  159.         TSR.Right = i + 2 + lSegmentSpacing
  160.         FillRect m_hDC, TSR, hBR
  161.     Next i
  162.     
  163.   Else
  164.     For i = TBR.Bottom To TBR.Top + lSegmentWidth Step -(lSegmentWidth + lSegmentSpacing)
  165.         TSR.Top = i - 2
  166.         TSR.Bottom = i - 2 + lSegmentSpacing
  167.         FillRect m_hDC, TSR, hBR
  168.     Next i
  169.     
  170.   End If
  171.   
  172.   DeleteObject hBR
  173.   
  174. End Sub
  175. Private Sub pDrawBorder()
  176.   Dim RTemp As RECT
  177.   
  178.   Let RTemp = TR
  179.   
  180.   RTemp.Left = TR.Left + 1: RTemp.Top = TR.Top + 1
  181.   DrawRectangle RTemp, GetLngColor(&HBEBEBE), m_hDC
  182.   RTemp.Left = TR.Left + 1: RTemp.Top = TR.Top + 2: RTemp.Right = TR.Right - 1: RTemp.Bottom = TR.Bottom - 1
  183.   DrawRectangle RTemp, GetLngColor(&HEFEFEF), m_hDC
  184.   DrawRectangle TR, GetLngColor(&H686868), m_hDC
  185.   
  186.   Call SetPixelV(m_hDC, 1, 1, GetLngColor(&H686868))
  187.   Call SetPixelV(m_hDC, TR.Right - 2, 1, GetLngColor(&H686868))
  188.   Call SetPixelV(m_hDC, 1, TR.Bottom - 2, GetLngColor(&H686868))
  189.   Call SetPixelV(m_hDC, TR.Right - 2, TR.Bottom - 2, GetLngColor(&H686868))
  190.   
  191. End Sub
  192. Private Sub PBarDraw()
  193.   Dim TempRect As RECT
  194.   Dim ITemp   As Long
  195.   
  196.   If m_Orientation = 0 Then
  197.     
  198.     TempRect.Left = TBR.Right
  199.     TempRect.Right = 2
  200.     TempRect.Top = 8
  201.     TempRect.Bottom = TR.Bottom - 6
  202.     
  203.     
  204.     
  205.     If m_Scrolling = ccScrollingSearch Then
  206.         GoSub HorizontalSearch
  207.     Else
  208.         DrawGradient m_hDC, 2, 3, TBR.Right - 2, 6, GetRGBColors(ShiftColorXP(m_Color, 150)), GetRGBColors(m_Color)
  209.         DrawFillRectangle TempRect, m_Color, m_hDC
  210.         DrawGradient m_hDC, 2, TempRect.Bottom - 2, TBR.Right - 2, 6, GetRGBColors(m_Color), GetRGBColors(ShiftColorXP(m_Color, 150))
  211.     End If
  212.     
  213.   Else
  214.     
  215.     TempRect.Left = 7
  216.     TempRect.Right = TR.Right - 8
  217.     TempRect.Top = TBR.Top
  218.     TempRect.Bottom = TR.Bottom
  219.     
  220.     
  221.     If m_Scrolling = ccScrollingSearch Then
  222.         GoSub VerticalSearch
  223.     Else
  224.         DrawGradient m_hDC, 2, TBR.Top, 6, TR.Bottom, GetRGBColors(ShiftColorXP(m_Color, 150)), GetRGBColors(m_Color), 0
  225.         DrawFillRectangle TempRect, m_Color, m_hDC
  226.         DrawGradient m_hDC, TR.Right - 8, TBR.Top, 6, TR.Bottom, GetRGBColors(m_Color), GetRGBColors(ShiftColorXP(m_Color, 150)), 0
  227.     End If
  228.     
  229.     
  230.   End If
  231.   
  232.   Exit Sub
  233.   
  234. HorizontalSearch:
  235.   
  236.   
  237.   For ITemp = 0 To 2
  238.     
  239.     With TempRect
  240.         .Left = TBR.Right + ((lSegmentSpacing + 10) * ITemp)
  241.         .Right = .Left + 10
  242.         .Top = 8
  243.         .Bottom = TR.Bottom - 6
  244.         DrawGradient m_hDC, .Left, 3, 10, 6, GetRGBColors(ShiftColorXP(m_Color, 220 - (40 * ITemp))), GetRGBColors(ShiftColorXP(m_Color, 200 - (40 * ITemp)))
  245.         DrawFillRectangle TempRect, ShiftColorXP(m_Color, 200 - (40 * ITemp)), m_hDC
  246.         DrawGradient m_hDC, .Left, .Bottom - 2, 10, 6, GetRGBColors(ShiftColorXP(m_Color, 200 - (40 * ITemp))), GetRGBColors(ShiftColorXP(m_Color, 220 - (40 * ITemp)))
  247.     End With
  248.     
  249.   Next ITemp
  250.   
  251.   Return
  252.   
  253. VerticalSearch:
  254.   
  255.   
  256.   For ITemp = 0 To 2
  257.     
  258.     With TempRect
  259.         .Left = 8
  260.         .Right = TR.Right - 8
  261.         .Top = TBR.Top + ((lSegmentSpacing + 10) * ITemp)
  262.         .Bottom = .Top + 10
  263.         DrawGradient m_hDC, 2, .Top, 6, 10, GetRGBColors(ShiftColorXP(m_Color, 220 - (40 * ITemp))), GetRGBColors(ShiftColorXP(m_Color, 200 - (40 * ITemp)))
  264.         DrawFillRectangle TempRect, ShiftColorXP(m_Color, 200 - (40 * ITemp)), m_hDC
  265.         DrawGradient m_hDC, .Right, .Top, 6, 10, GetRGBColors(ShiftColorXP(m_Color, 200 - (40 * ITemp))), GetRGBColors(ShiftColorXP(m_Color, 220 - (40 * ITemp)))
  266.     End With
  267.     
  268.   Next ITemp
  269.   
  270.   Return
  271.   
  272.   
  273.   
  274. End Sub
  275. Private Function DrawTexto()
  276.   Dim ThisText As String
  277.   
  278.   If m_Scrolling = ccScrollingSearch Then
  279.     ThisText = "帮助"
  280.   Else
  281.   ThisText = m_Value & "/" & m_Max
  282.   End If
  283.   
  284.   If (m_ShowText) Then
  285.     Set iFnt = Font
  286.     hFntOld = SelectObject(m_hDC, iFnt.hFont)
  287.     SetBkMode m_hDC, 1
  288.     SetTextColor m_hDC, vbBlack
  289.     DrawText m_hDC, ThisText, -1, TR, DT_SINGLELINE Or 1 Or 4
  290.     SelectObject m_hDC, hFntOld
  291.   End If
  292.   
  293. End Function
  294. Private Function GetLngColor(Color As LongAs Long
  295.   
  296.   If (Color And &H80000000) Then
  297.     GetLngColor = GetSysColor(Color And &H7FFFFFFF)
  298.   Else
  299.     GetLngColor = Color
  300.   End If
  301. End Function
  302. Private Function GetRGBColors(Color As LongAs RGB
  303.   
  304.   Dim HexColor As String
  305.   
  306.   HexColor = String(6 - Len(Hex(Color)), "0") & Hex(Color)
  307.   GetRGBColors.R = "&H" & Mid(HexColor, 5, 2) & "00"
  308.   GetRGBColors.G = "&H" & Mid(HexColor, 3, 2) & "00"
  309.   GetRGBColors.B = "&H" & Mid(HexColor, 1, 2) & "00"
  310. End Function
  311. Private Sub DrawRectangle(ByRef BRect As RECT, ByVal Color As LongByVal HDC As Long)
  312.   
  313.   Dim hBrush As Long
  314.   
  315.   hBrush = CreateSolidBrush(Color)
  316.   FrameRect HDC, BRect, hBrush
  317.   DeleteObject hBrush
  318.   
  319. End Sub
  320. Private Function ShiftColorXP(ByVal MyColor As LongByVal Base As LongAs Long
  321.   
  322.   Dim R As Long, G As Long, B As Long, Delta As Long
  323.   
  324.   R = (MyColor And &HFF)
  325.   G = ((MyColor / &H100) Mod &H100)
  326.   B = ((MyColor / &H10000) Mod &H100)
  327.   
  328.   Delta = &HFF - Base
  329.   
  330.   B = Base + B * Delta / 
  331.   G = Base + G * Delta / 
  332.   R = Base + R * Delta / 
  333.   
  334.   If R > 255 Then R = 255
  335.   If G > 255 Then G = 255
  336.   If B > 255 Then B = 255
  337.   
  338.   ShiftColorXP = R + 256& * G + 65536 * B
  339.   
  340. End Function
  341. Private Sub DrawGradient( _
  342.   ByVal cHdc As Long, _
  343.   ByVal X As Long, _
  344.   ByVal Y As Long, _
  345.   ByVal X2 As Long, _
  346.   ByVal Y2 As Long, _
  347.   ByRef Color1 As RGB, _
  348.   ByRef Color2 As RGB, _
  349.   Optional Direction = 1)
  350.   
  351.   Dim Vert(1) As TRIVERTEX
  352.   Dim gRect   As GRADIENT_RECT
  353.   
  354.   With Vert(0)
  355.     .X = X
  356.     .Y = Y
  357.     .Red = Color1.R
  358.     .Green = Color1.G
  359.     .Blue = Color1.B
  360.     .Alpha = 0
  361.   End With
  362.   
  363.   With Vert(1)
  364.     .X = Vert(0).X + X2
  365.     .Y = Vert(0).Y + Y2
  366.     .Red = Color2.R
  367.     .Green = Color2.G
  368.     .Blue = Color2.B
  369.     .Alpha = 0
  370.   End With
  371.   
  372.   gRect.UPPERLEFT = 1
  373.   gRect.LOWERRIGHT = 0
  374.   
  375.   GradientFillRect cHdc, Vert(0), 2, gRect, 1, Direction
  376.   
  377. End Sub
  378. Private Sub DrawFillRectangle(ByRef hRect As RECT, ByVal Color As LongByVal MyHdc As Long)
  379.   
  380.   Dim hBrush As Long
  381.   
  382.   hBrush = CreateSolidBrush(GetLngColor(Color))
  383.   FillRect MyHdc, hRect, hBrush
  384.   DeleteObject hBrush
  385.   
  386. End Sub
  387. Private Sub RoundCorners(ByRef RcItem As RECT, ByVal m_hWnd As Long)
  388.   
  389.   Dim rgn1 As Long, rgn2 As Long, rgnNorm As Long
  390.   
  391.   rgnNorm = CreateRectRgn(0, 0, RcItem.Right, RcItem.Bottom)
  392.   rgn2 = CreateRectRgn(0, 0, 0, 0)
  393.   
  394.   rgn1 = CreateRectRgn(0, 0, 2, 1)
  395.   CombineRgn rgn2, rgnNorm, rgn1, RGN_DIFF
  396.   DeleteObject rgn1
  397.   rgn1 = CreateRectRgn(0, RcItem.Bottom, 2, RcItem.Bottom - 1)
  398.   CombineRgn rgnNorm, rgn2, rgn1, RGN_DIFF
  399.   DeleteObject rgn1
  400.   rgn1 = CreateRectRgn(RcItem.Right, 0, RcItem.Right - 2, 1)
  401.   CombineRgn rgn2, rgnNorm, rgn1, RGN_DIFF
  402.   DeleteObject rgn1
  403.   rgn1 = CreateRectRgn(RcItem.Right, RcItem.Bottom, RcItem.Right - 2, RcItem.Bottom - 1)
  404.   CombineRgn rgnNorm, rgn2, rgn1, RGN_DIFF
  405.   DeleteObject rgn1
  406.   rgn1 = CreateRectRgn(0, 1, 1, 2)
  407.   CombineRgn rgn2, rgnNorm, rgn1, RGN_DIFF
  408.   DeleteObject rgn1
  409.   rgn1 = CreateRectRgn(0, RcItem.Bottom - 1, 1, RcItem.Bottom - 2)
  410.   CombineRgn rgnNorm, rgn2, rgn1, RGN_DIFF
  411.   DeleteObject rgn1
  412.   rgn1 = CreateRectRgn(RcItem.Right, 1, RcItem.Right - 1, 2)
  413.   CombineRgn rgn2, rgnNorm, rgn1, RGN_DIFF
  414.   DeleteObject rgn1
  415.   rgn1 = CreateRectRgn(RcItem.Right, RcItem.Bottom - 1, RcItem.Right - 1, RcItem.Bottom - 2)
  416.   CombineRgn rgnNorm, rgn2, rgn1, RGN_DIFF
  417.   
  418.   DeleteObject rgn1
  419.   DeleteObject rgn2
  420.   SetWindowRgn m_hWnd, rgnNorm, True
  421.   DeleteObject rgnNorm
  422. End Sub
  423. Private Function ThDC(Width As Long, Height As LongAs Long
  424.   If m_ThDC = 0 Then
  425.     If (Width > 0) And (Height > 0) Then
  426.         pCreate Width, Height
  427.     End If
  428.   Else
  429.     If Width > m_lWidth Or Height > m_lHeight Then
  430.         pCreate Width, Height
  431.     End If
  432.   End If
  433.   ThDC = m_ThDC
  434. End Function
  435. Private Sub pCreate(ByVal Width As LongByVal Height As Long)
  436.   Dim lhDCC As Long
  437.   pDestroy
  438.   lhDCC = CreateDC("DISPLAY"""""ByVal 0&)
  439.   If Not (lhDCC = 0) Then
  440.     m_ThDC = CreateCompatibleDC(lhDCC)
  441.     If Not (m_ThDC = 0) Then
  442.         m_hBmp = CreateCompatibleBitmap(lhDCC, Width, Height)
  443.         If Not (m_hBmp = 0) Then
  444.           m_hBmpOld = SelectObject(m_ThDC, m_hBmp)
  445.           If Not (m_hBmpOld = 0) Then
  446.             m_lWidth = Width
  447.             m_lHeight = Height
  448.             DeleteDC lhDCC
  449.             Exit Sub
  450.           End If
  451.         End If
  452.     End If
  453.     DeleteDC lhDCC
  454.     pDestroy
  455.   End If
  456. End Sub
  457. Public Sub pDraw( _
  458.   ByVal HDC As Long, _
  459.   Optional ByVal xSrc As Long = 0, Optional ByVal ySrc As Long = 0, _
  460.   Optional ByVal WidthSrc As Long = 0, Optional ByVal HeightSrc As Long = 0, _
  461.   Optional ByVal xDst As Long = 0, Optional ByVal yDst As Long = 0 _
  462.   )
  463.   If WidthSrc <= 0 Then WidthSrc = m_lWidth
  464.   If HeightSrc <= 0 Then HeightSrc = m_lHeight
  465.   BitBlt HDC, xDst, yDst, WidthSrc, HeightSrc, m_ThDC, xSrc, ySrc, vbSrcCopy
  466.   
  467. End Sub
  468. Private Sub pDestroy()
  469.   If Not m_hBmpOld = 0 Then
  470.     SelectObject m_ThDC, m_hBmpOld
  471.     m_hBmpOld = 0
  472.   End If
  473.   If Not m_hBmp = 0 Then
  474.     DeleteObject m_hBmp
  475.     m_hBmp = 0
  476.   End If
  477.   If Not m_ThDC = 0 Then
  478.     DeleteDC m_ThDC
  479.     m_ThDC = 0
  480.   End If
  481.   m_lWidth = 0
  482.   m_lHeight = 0
  483. End Sub
  484. Private Sub UserControl_Initialize()
  485.   
  486.   
  487.   Dim fnt As New StdFont
  488.   fnt.Name = "Tahoma"
  489.   fnt.Size = 8
  490.   Set Font = fnt
  491.   
  492.   With UserControl
  493.     .BackColor = vbWhite
  494.     .ScaleMode = vbPixels
  495.   End With
  496.   
  497.   HDC = UserControl.HDC
  498.   hwnd = UserControl.hwnd
  499.   m_Max = 100
  500.   m_Min = 0
  501.   m_Value = 0
  502.   m_Orientation = ccOrientationHorizontal
  503.   m_Scrolling = ccScrollingStandard
  504.   m_Color = GetLngColor(vbHighlight)
  505.   DrawProgressBar
  506.   
  507. End Sub
  508. Private Sub UserControl_Paint()
  509.   
  510.   Dim cRect As RECT
  511.   
  512.   DrawProgressBar
  513.   
  514.   With UserControl
  515.     GetClientRect .hwnd, cRect
  516.     RoundCorners cRect, .hwnd
  517.   End With
  518.   
  519. End Sub
  520. Private Sub UserControl_Resize()
  521.   HDC = UserControl.HDC
  522. End Sub
  523. Private Sub UserControl_Terminate()
  524.   pDestroy
  525. End Sub
  526. Public Property Get Color() As OLE_COLOR
  527.   Color = m_Color
  528. End Property
  529. Public Property Let Color(ByVal lColor As OLE_COLOR)
  530.   m_Color = GetLngColor(lColor)
  531. End Property
  532. Public Property Get Font() As IFont
  533.   Set Font = m_fnt
  534. End Property
  535. Public Property Set Font(ByRef fnt As IFont)
  536.   Set m_fnt = fnt
  537. End Property
  538. Public Property Let Font(ByRef fnt As IFont)
  539.   Set m_fnt = fnt
  540. End Property
  541. Public Property Get hwnd() As Long
  542.   hwnd = m_hWnd
  543. End Property
  544. Public Property Let hwnd(ByVal chWnd As Long)
  545.   m_hWnd = chWnd
  546. End Property
  547. Public Property Get HDC() As Long
  548.   HDC = m_hDC
  549. End Property
  550. Public Property Let HDC(ByVal cHdc As Long)
  551.   
  552.   m_hDC = ThDC(UserControl.ScaleWidth, UserControl.ScaleHeight)
  553.   
  554.   If m_hDC = 0 Then
  555.     m_hDC = UserControl.HDC
  556.   Else
  557.     m_MemDC = True
  558.   End If
  559. End Property
  560. Public Property Get Min() As Long
  561.   Min = m_Min
  562. End Property
  563. Public Property Let Min(ByVal cMin As Long)
  564.   m_Min = cMin
  565. End Property
  566. Public Property Get Max() As Long
  567.   Max = m_Max
  568. End Property
  569. Public Property Let Max(ByVal cMax As Long)
  570.   m_Max = cMax
  571. End Property
  572. Public Property Get Orientation() As cOrientation
  573.   Orientation = m_Orientation
  574. End Property
  575. Public Property Let Orientation(ByVal cOrientation As cOrientation)
  576.   m_Orientation = cOrientation
  577. End Property
  578. Public Property Get Scrolling() As cScrolling
  579.   Scrolling = m_Scrolling
  580. End Property
  581. Public Property Let Scrolling(ByVal lScrolling As cScrolling)
  582.   m_Scrolling = lScrolling
  583. End Property
  584. Public Property Get ShowText() As Boolean
  585.   ShowText = m_ShowText
  586. End Property
  587. Public Property Let ShowText(ByVal bShowText As Boolean)
  588.   m_ShowText = bShowText
  589.   DrawProgressBar
  590. End Property
  591. Public Property Get Value() As Long
  592.   Value = m_Value
  593. End Property
  594. Public Property Let Value(ByVal cValue As Long)
  595.   m_Value = cValue
  596.   DrawProgressBar
  597. End Property
  598. Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
  599.   
  600.   Color = PropBag.ReadProperty("Color", vbHighlight)
  601.   Max = PropBag.ReadProperty("Max", 100)
  602.   Min = PropBag.ReadProperty("Min", 0)
  603.   Orientation = PropBag.ReadProperty("Orientation", ccOrientationHorizontal)
  604.   Scrolling = PropBag.ReadProperty("Scrolling", ccScrollingStandard)
  605.   ShowText = PropBag.ReadProperty("ShowText"False)
  606.   Value = PropBag.ReadProperty("Value", 0)
  607.   
  608. End Sub
  609. Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
  610.   
  611.   Call PropBag.WriteProperty("Color", m_Color, vbHighlight)
  612.   Call PropBag.WriteProperty("Max", m_Max, 100)
  613.   Call PropBag.WriteProperty("Min", m_Min, 0)
  614.   Call PropBag.WriteProperty("Orientation", m_Orientation, ccOrientationHorizontal)
  615.   Call PropBag.WriteProperty("Scrolling", m_Scrolling, ccScrollingStandard)
  616.   Call PropBag.WriteProperty("ShowText", m_ShowText, False)
  617.   Call PropBag.WriteProperty("Value", m_Value, 0)
  618.   
  619. End Sub

上面的代码有一个bug,就是当值小于0时会出问题,你可以自己改动一下,在代码里做下判断.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

TakiCN

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值