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

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

VB进度条 游戏血条控件相关推荐

  1. VB.net数据库编程中DataGrid控件的使用技巧

    VB.net数据库编程中DataGrid控件的使用技巧 如何用同一个DataGrid显示不同的数据表:如何用DataGrid显示主表/明细表的内容:如何用DataGrid分页显示或编辑数据表的记录.这 ...

  2. Android游戏开发系统控件-CheckBox

    Android游戏开发系统控件-CheckBox 2012/5/11 星期五 CheckBox是Android系统最普通的UI控件,继承了Button按钮 下面通过一个实例来学习 作者:wwj 功能: ...

  3. Android游戏开发系统控件-Dialog

    Android游戏开发系统控件-Dialog Dialog(对话框)在Android应用开发中经常用到,下面是学习<Android游戏编程从零开始>一书,关于Dialog的初步学习. 创建 ...

  4. VB根据窗体自动调整窗体内控件大小 注:实用,可以直接引用

    代码如下: Option Explicit Private ObjOldWidth     As Long       '保存窗体的原始宽度 Private ObjOldHeight     As L ...

  5. C#之进度条:用ProgressBar控件实现一边在后台进行算法计算一边在界面显示进度条,需借用BackgroundWorker

    近期有个任务需要用到进度条,发现只是单纯设置ProgressBar控件的值的话,并没办法同时实现算法计算和界面进度条显示,这时候需要使用到BackgroundWorker. 下面直接用代码举例说明,如 ...

  6. 组态王怎么做进度条_3分钟学会超实用||进度条amp;游戏血条的制作方法!

    最近有很多小伙伴盯上了我们一看就会的进度条和血条效果,问是怎么做的,像这种进度条一般放置于视频正片底部,用来做章节内容提示,喵酱今天就来给大家解密一下这些效果的制作方法. (视频教程在文末) 文字教程 ...

  7. 优秀课程案例:使用Scratch模拟游戏中的血条显示-血条模拟器!

    点击上面微信号关注我关注我哟每天坚持推送文章,争取做到日更,喜欢的可以设置星标,并分享点赞我们的文章,非常感谢大家的支持,您的点击的在看就是我们的动力! 最近两天我们分享了抽奖大转盘的案例:优秀课程案 ...

  8. cocos2dx-lua 之 ProgressTimer 条形进度条 简单血条的实现

    cocos2dx-lua 简单血条的实现 所用资源: blood_bg.png :    blood_red.png  直接贴代码: local BloodProgressBar = class(&q ...

  9. 按键精灵游戏血条横向保护代码

    Function 横向血条保护(百分比)血条颜色 = GetPixelColor(713 + (220 * 百分比 / 100), 468)R = Right(血条颜色, 2)G = Mid(血条颜色 ...

  10. JavaFX七巧板游戏:布局控件

    用于布局的控件 JavaFX七巧板游戏:布局入门到放弃一文把用于布局的窗格(Pane)拉了一遍,里面提到有一些控件,也有布局的作用. 明显,控件与窗格一样,是Region的子类:与窗格不同的是,控件有 ...

最新文章

  1. C#的简单不安全双向“混淆”
  2. Spring MVC整合Velocity
  3. 第二讲,我们来谈谈:“什么是二进制”
  4. 区块链学堂(2):最简单的智能合约
  5. `MediaDevices.getUserMedia` `undefined` 的问题
  6. android tag的作用,Android中的Context的作用(2)
  7. c# 指定打开某个路径下的CMD_【自学C#】|| 笔记 25 文件的操作
  8. crontab 不执行解决方案
  9. 平板连接远程Linux,如何从Android平板电脑远程控制Ubuntu | MOS86
  10. 【PMP认证考试感悟】走向管理的开始
  11. 列举5种常见的计算机硬件主要有哪些,计算机硬件组成有哪些
  12. Java实用工具类-将汉字转为拼音
  13. python 余弦定理_自己实现文本相似度算法(余弦定理)
  14. AI工具是帮手还是助手:
  15. 蓝桥杯:C语言实现字母图形
  16. linux下定时清理日志任务
  17. 决策树,逻辑回归,PCA-算法面经
  18. 面向DevSecOps的编码安全指南|JavaScript篇
  19. 2021年10个最美的边框效果,CSS实现,可以直接使用
  20. pcl::IOException what() [pcl::PCDWriter::writeASCII] Could not open file for writing

热门文章

  1. 板翅式换热器翅片表面传热与阻力特性性能分析
  2. Mac OS下phonegap开发环境的建立
  3. 谷歌浏览器32位安装包_Chromium内核的edge浏览器终于来了,试用了半天,发现真香!...
  4. linux psftp,使用PSFTP实现Windows、Linux之间的文件传输
  5. 巧用Procexp找出弹窗广告真凶
  6. 定制一款铝合金型材的流程
  7. 使用国产化的TongWeb服务器使用手册
  8. Java Filter——敏感词汇过滤
  9. matlab能打开mdl文件吗,simulink打开mdl文件的问题
  10. android 简单锁屏代码,【简单代码】默认锁屏代码第二弹~