A year ago, a little experience in the compilation of the OCX control was shared together in VB.
When the property is running and the design mode, the property value is lost, you can use WriteProperties to save the attribute value, then read it with readproperties, the specific situation is as follows:
1. When the design mode is switched forward, use WriteProperties to save attribute values, because this value is used during runtime, so readproperties read.
2. When switching to the design mode at the beginning, the value of the control is required to save the control, so it does not call WriteProperties, and the value directly read directly in the design mode.
3, WriteProperties and Readproperties events are only valid in design debugging, and they are no longer valid after compiling as an EXE file. This two events and propbag objects exist only for convenience.
Routines: 'This control is a combination of Text and Updown controls. Use UPDOWN to change the data value' can also be manually change the TEXT value '' DIM M_UPMAX AS Longdim m_downmin as longdim m_value as longdim m_enabled as boolean
PRIVATE SUB TEXT1_CHANGE () ON Error Goto Erdim Txti As Long
'Txti text1 to zero value stored txti = CLng (text1.Text) If txti> UpDown1.Max Then text1.Text = UpDown1.MaxEnd IfIf txti Err: text1.text = updown1.valueend Sub PRIVATE SUB Updown1_change () text1.text = updown1.valueend Sub Private Sub UserControl_Resize () On Error Resume NextDim t As LongDim b As Longt = UserControl.Width - UpDown1.Widthb = UserControl.Height - 1text1.Width = ttext1.Height = btext1.Move 0, 0UpDown1.Move t, 0UpDown1.Height = Bend Sub Public property Get Upmax () as longupmax = m_upmaxnd property Public Property Let Upmax (Byval VNewValue As Long) M_upmax = VNewValueUpdown1.max = m_upmaxpropertychanged "Upmax" End Property Public property get down () as longdownmin = m_downminend property Public property Let Downmin (Byval VNewValue As Long) m_downmin = vnewvalueUpdown1.min = VNewValuePropertyChanged "Downmin" End Property Private Sub UserControl_WriteProperties (PropBag As PropertyBag) Call PropBag.WriteProperty ( "UpMax", m_UpMax, 0) Call PropBag.WriteProperty ( "DownMin", m_DownMin, 0) Call PropBag.WriteProperty ( "Value", CLng (text1.Text), 0) Call PropBag.WriteProperty ( "Enabled", m_Enabled, True) End SubPrivate Sub UserControl_ReadProperties (PropBag As PropertyBag) 'must have a default value when using PropBag.ReadProperty, or if the property value has not changed in the design (' that is not Use WriteProperty to save attribute values) If you can't read, it will generate "Runtime Error" m_UpMax = PropBag.ReadProperty ( "UpMax", 0) m_DownMin = PropBag.ReadProperty ( "DownMin", 0) m_value = PropBag.ReadProperty ( "Value", 0) m_Enabled = PropBag.ReadProperty ( "Enabled", True) UpDown1. Max = m_upmaxupdown1.min = m_downminupdown1.value = m_valueUPdown1.enabled = m_enabledtext1.text = m_Valuetext1.enabled = m_enabledend Sub Public property get value () as longattribute value.vb_usermemid = 0m_value = clng (text1.text) value = m_ValueEnd Property Public Property Let Value (ByVal vNewValue As Long) If vNewValue> m_UpMax Then m_value = m_UpMaxElseIf vNewValue PropertyChanged "Value" End Property Public property get enabled () as booleaNabled = M_ENABLEDEND PROPERTY Public Property Let Enabled (Byval VNewValue As Boolean) M_enabled = VNewValueUpdown1.enabled = m_enabledtext1.enabled = m_enabledpropertychanged "enabled" End Property You can also click here to download the control source program Limited horizontal, welcome to exchange MSN: Equn_cn@hotmail.com