Encapsulating Maskedit controls with ActiveX controls-resolving problems that cannot be bound

Source: Internet
Author: User
Tags valid

The reference is determined or changed to a generic ActiveX control.

(1) A new ActiveX control project.

Place a Maskedit control on.

The design of the test is as follows:

The Name:datadate of UserControl.

UserControl's Databindingbehavior setting 1-vvbsimplebound

The name:mskdate of Maskedtbox.

(2). The new data is used for binding. The operation is as follows (I use it as a complex system, which I might say is not the same).

Open menu: Gain set--> add-in administrator.

Download the visual Basic Acitvex Control Interface Essence and activate it.

Run to: Create a custom interface to add a property:datevalue (this is the one you want to manipulate).

The next step is to make sure that the system:

The binding of common items to mskdate. If the mskdate is not relevant and can be tied to the UserControl.

Set the date type for the DateValue data type in a common item

Complete the above operation.

(3). The datevalue is set to the data binding to the material.

Click UserControl.

Open Tools---> program.

Select DateValue from the name fence.

Check the following options in the data link:

"Material connectivity Function"

"Call Canpropertychange before changing the value of the metal.

"Instant Update"

At this time DataValue is a data binding function. The nature of this control increases the number of things like Datasource.datafield.

(4). Edit and write the codes.

A. Set the control size.

Private Sub UserControl_Resize()
   MskDate.Move 0, 0, UserControl.Width, usercontrol.Height
  End Sub
       b.將dateValue的代碼修正如下:
     Public Property Let DateValue(ByVal New_DateValue As Date)
    m_DateValue = New_DateValue
    PropertyChanged "DateValue"
    If Not IsEmpty(m_DateValue) Then
      If IsDate(m_DateValue) Then
        If Year(m_DateValue) > 1970 Then
          MskDate.Text = Format(m_DateValue, "yyyy/mm/dd")
        Else
          MskDate.Text = "____/__/__"
        End If
      Else
        MskDate.Text = "____/__/__"
      End If
    Else
      MskDate.Text = "____/__/__"
    End If
  End Property

, this is where the value of the mskdate is justified, and if it is valid, it is shown in the other way.

Private Sub MskDate_Validate(Cancel As Boolean)
If IsDate(Trim(MskDate.Text)) Then
   If CanPropertyChange("DateValue") Then
     m_DateValue = CDate(MskDate.Text)
     PropertyChanged "DateValue"
   End If
Else
   MsgBox "Invalid date value!", vbExclamation, "Date Error!"
  
   If Not IsEmpty(m_DateValue) Then
     If IsDate(m_DateValue) Then
       If Year(m_DateValue) > 1970 Then
         MskDate.Text = Format(m_DateValue, "yyyy/mm/dd")
       Else
         MskDate.Text = "____/__/__"
       End If
     Else
       MskDate.Text = "____/__/__"
     End If
   Else
     MskDate.Text = "____/__/__"
   End If
  
End If
End Sub

' This is to determine whether the value of mskdate is valid, if valid, adjust the propertychanged ' DateValue '. The data will change the value of the data DataField.

Finally, the project is translated into a control datadate.ocx to be referenced, DataValue is the text of the text in the text can be directly used in the file.

Use the above method to customize the data to bind the control to our special processing.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.