VB can show that the preparation of a percentage of the progress since the definition of control
Operating Results:

Design Method:
1. UserControl add a Label control Label1, to be set flat, used for the frame. Add two PictureBox control PictureBox1 as progress instructions PictureBox2 controls background as a control.

2. By adding the following code
Option Explicit
'Definition of private variables used to store property values
Private mvarMax As Long
Private mvarMin As Long
Private mvarValue As Long
Private Rate As String
Private Sub UserControl_Initialize ()
'Initialization
Picture2.BackColor = vbBlue
End Sub
Public Property Get BackColor () As OLE_COLOR
'Read BackColor property
BackColor = Picture1.BackColor
End Property
Public Property Let BackColor (ByVal vNewValue As OLE_COLOR)
'Attribute set BackColor
Picture1.BackColor = vNewValue
End Property
Private Sub UserControl_InitProperties ()
'Initialization attribute
Max = 100
Min = 0
Value = 0
End Sub
Private Sub UserControl_ReadProperties (PropBag As PropertyBag)
'Read from the attribute set in the form of attribute values
MvarMax = PropBag.ReadProperty ( "Max", 100)
MvarMin = PropBag.ReadProperty ( "Min", 0)
'Value attribute value not available here, mainly to imitate comes with the progress of the VB Controls
'MvarValue = PropBag.ReadProperty ( "Value", 0)
End Sub
Private Sub UserControl_WriteProperties (PropBag As PropertyBag)
'Save from the attribute set in the form of attribute values
PropBag.WriteProperty "Max", mvarMax, 100
PropBag.WriteProperty "Min" mvarMin, 0
'PropBag.WriteProperty "Value" mvarValue, 0
End Sub
Private Sub UserControl_Resize ()
'Resize incident
Label1.Move 0, 0, UserControl.Width / Screen.TwipsPerPixelX, UserControl.Height / Screen.TwipsPerPixelY
Picture1.Move 1, 1, UserControl.Width / Screen.TwipsPerPixelX - 2, UserControl.Height / Screen.TwipsPerPixelY - 2
Picture2.Move 1, 1, 1, UserControl.Height / Screen.TwipsPerPixelY - 2
End Sub
Public Property Get Max () As Long
'Read Max Properties
Max = mvarMax
End Property
Public Property Let Max (ByVal vNewValue As Long)
'Max attribute settings
MvarMax = vNewValue
If vNewValue <Min Then Err.Raise "1001", "Max must be greater than Min"
End Property
Public Property Get Min () As Long
'Read Min attributes
Min = mvarMin
End Property
Public Property Let Min (ByVal vNewValue As Long)
'Attribute set Min
If vNewValue> Max Then Err.Raise "1000", "Min must be less than Max"
MvarMin = vNewValue
End Property
Public Property Get Value () As Long
'Read Value attribute
Value = mvarValue
End Property
Public Property Let Value (ByVal vNewValue As Long)
'Value attribute settings
'Principle in the two PictureBox is in a different color print percentage progress
Dim DX As Long, DY As Long
If vNewValue> Max Then Err.Raise "1002", "Value is not greater than Max"
MvarValue = vNewValue
Picture2.Width = Value / (Max - Min) * (UserControl.Width / Screen.TwipsPerPixelX - 2)
Rate = Int (Value / (Max - Min) * 100) & "%"
DX = (Picture1.Width - Picture1.TextWidth (Rate)) / 2
DY = (Picture1.Height - Picture1.TextHeight (Rate)) / 2
Picture1.ForeColor = vbBlack
Picture2.ForeColor = vbWhite
If DX <Picture2.Width Then
Picture2.Cls
Picture2.CurrentX DX =
Picture2.CurrentY = DY
Picture2.Print Rate
Else
Picture1.Cls
Picture1.CurrentX DX =
Picture1.CurrentY = DY
Picture1.Print Rate
End If
End Property
3. Another new test works by adding a control of their own progress and the progress of a system of controls, by adding the following code:
Option Explicit
Private Sub Command1_Click ()
Unload Me
End Sub
Private Sub Timer1_Timer ()
MyProgressBar1.Value + 2 = myProgressBar1.Value
ProgressBar1.Value + 2 = ProgressBar1.Value
If myProgressBar1.Value = = False myProgressBar1.Max Then Timer1.Enabled
End Sub
OK. Look at the effect of running it.
Tags: vb








0 Comments to “VB can show that the preparation of a percentage of the progress since the definition of control”
No Comments. Send your comment.
Leave a Reply
You must be logged in to post a comment.