VB writes a customized schedule control with a percentage

zhaozj2021-02-16  57

running result:

Design method:

1. Add a Label control Label1 in UserControl, set it to a plane, used to do the box. Add two PictureBox control PictureBox1 as a progress indication, PictureBox2 control is a control background.

2. Add the following code

Option expedition

'Define private variables for Storage Property Values ​​Private Mvarmax As Longprivate Mvarmin As Longprivate MvarValue As Long

Private Rate As String

Private sub usercontrol_initialize () 'Initialization Picture2.backcolor = VBLUEEND SUB

Public property get backcolor () AS OLE_COLOR 'Read BackColor Properties Backcolor = Picture1.Backcolorend Property

Public property Let BackColor (Byval VNewValue As Ole_Color) Set Backcolor Property Picture1.BackColor = VNewValueEnd Property

Private sub usercontrol_initproperties () 'Initialization Properties MAX = 100 min = 0 value = 0nd SUB

Private Sub UserControl_readproperties (Propbag As Propertybag) 'Reads the attribute value set from the properties form mvarmax = propbag.readproperty ("max", 100) mvarmin = propbag.readproperty ("min", 0)' Value attribute value here Provided, mainly to imitate the progress of the VB comes with the progress strip control 'mvarvalue = propbag.readproperty ("value", 0) end sub

Private Sub UserControl_WriteProperties (PropBag As PropertyBag) 'stored attribute value PropBag.WriteProperty "Max" from the attribute setting form, mvarMax, 100 PropBag.WriteProperty "Min", mvarMin, 0' PropBag.WriteProperty "Value", mvarValue, 0End Sub

Private Sub UserControl_Resize () 'Resize event 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.twipsPixely - 2END SUB

Public property get max () as long 'read max attribute Max = mvarmaxend property

Public Property Let Max (Byval VNewValue As Long "Sets Max Properties Mvarmax = VNewValue if VNewValue

Public property let Min (Byval VNewValue As Long "Sets MIN attribute if vnewvalue> max life err.raise" 1000 "," MIN must be smaller than max "mvarmin = vnewvalueend property

Public property get value () as long 'reading value attribute value = mvarvalueend property

Public Property Let Value 'Setting Value Properties' Principle Is Print Percentage Progress in Different Colors in Two Picturebox Download DX As Long, DY As Long

If VNEWVALUE> Max Then Err.raise "1002", "Value can't be larger 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

3. Newly build another test engineering, join an initial stripe control and a system's schedule control, add the following code:

Option expedition

Private sub fascist1_click () unload mend Sub

Private Sub Timer1_Timer () myProgressBar1.Value = myProgressBar1.Value 2 ProgressBar1.Value = ProgressBar1.Value 2 If myProgressBar1.Value = myProgressBar1.Max Then Timer1.Enabled = FalseEnd SubOK. Run to see results.

转载请注明原文地址:https://www.9cbs.com/read-15471.html

New Post(0)