Teach you how to make ActiveX controls with VB

Source: Internet
Author: User

Controls are also the most important part of programming as controls improve their status in visual programming. Many VB programmers may suffer from the lack of good-looking controls, today unstoppable to teach you how to make ActiveX controls.

First, the new project

1. Select the ActiveX control

2. Open the Project

We'll see one more UserControl in the engineering Explorer, which is equivalent to the form in the application.

Here are some of the properties of UserControl

Properties of the UserControl
BackStyle Decide whether UserControl is transparent. 1 is opaque and 0 is transparent. Default any 1
ToolboxBitmap The value is a picture path, which is an icon displayed on the VB toolbar, 16*15 pixels in size, and supports bmp,jpg
Public Determines whether this user control is available to other programs, defaults to ture, and can
Height Control height
Width Control width

Here are a few events that are different from form to UserControl

Events in UserControl
Initialize The control's initialization event, which is triggered when the control is placed on the form at design time or when the form load or unload is running
InitProperties Triggered when a new instance of an object is created
Resize This event occurs when an object is first displayed or when the window state of an object changes
Show Used to display MDIForm or Form objects
Terminate All references to an instance of the Nothing,form, MDIForm, User control, property Page WebClass, DHTML page designer, or class are removed from memory by setting all the variables of the object involved. Or occurs when the last reference of an object loses scope.
Paint This event occurs when an object is moved or enlarged, or when a control that overrides the object is removed, partially or wholly, when the object is exposed.

Below, we are ready to start making our user control.

Second, add user events

The beginning of UserControl is only four basic events, such as Gotfoucs. So how do you add common events such as Click,mousemove? It's actually very simple.

1. Defining User Events

Event name () ' Defines user events


2. Triggering user Events

RaiseEvent event name ' Trigger user event '

3. Example

Event Click () ' Set the clicking Event
Private Sub Usercontrol1_click ()
RaiseEvent click ' Trigger Click event
End Sub

This is the simplest example of a clock that can be used to set the delay response of events and the effects of events.

Third, add user attributes

Properties are also important in the user control, let's look at how to add user attributes.

1. Defining attributes

Public Properties Get Property name () as data type
Property name = existing object. Attribute
End Property

2. Refresh properties When property changes

Public properties let attribute name (ByVal New_ property name as data type)
existing object. Attribute = New_ Property name
propertychanged property name

This is just the simplest refresh property, and you can add "if then Else" to determine whether the property is legitimate

3. Example

Place a Label1 on the UserControl1 and set a Caption property to Label1 caption.

Public Property Get Caption () as String
Caption = Label1.Caption ' Set Caption attribute
End Property
Public properties Let Caption (ByVal new_caption as String)
Label1.Caption = New_caption ' Refresh property
propertychanged ' Caption "
End Property


Iv. Use of skills

1. How to quickly add a property (1) Select the [Tools] menu and click [Add Procedure].
(2) Enter the property name and select the type [Properties].
(3) Click [OK] to finish adding the property.
Effect:

2. How to quickly add events

(1) Select the [Tools] menu and click [Add Procedure].
(2) Enter the event name and select the type of [Event].
(3) Click [OK] to finish adding the event.
Effect:

Goodbye, the end of this chapter. There will be two blog posts to introduce the example production, welcome to visit my blog: Unstoppable's blog

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.