Using VB to create ActiveX

Source: Internet
Author: User

Introduction

Edition makes creating an ActiveX control key as easy as creating a generic VB application. After reading this article, you will see how easy it is.

This article outlines the simple process of creating an ActiveX control key with VisualBasic. If you are already familiar with the various versions of VisualBasic, you will be able to create your first ActiveX control key in 10 minutes.

The following steps will guide you through the process of creating a control key that is usually called a "spinner control". The fine-tuning control key is a graphical ActiveX control key that enables the user to increase the reduced value with the mouse instead of the keyboard, and the following figure is a spinner control key.

Now you have a concept for the object you want to build. Here we go!

Step 1: Create a Test Container

Start controlcreationedition, light Standard.EXE, click Open, as shown in the following figure. This is to create the main application. This main application will be used as a test container for fine-tuning control keys.

Step 2: Add a blank ActiveX Control key engineering file.

Select the AddProject command from the File menu.

In the AddProject dialog box, point to ActiveXcontrol, and click Open.

Two engineering files need to be opened here. These engineering files are similar, as shown in the following figure. Note: A new control key is visible in the tool box (measured in Figure 5 and labeled with a number of 1). If you move the mouse over this key in Toolbox, a ToolTip will pop up showing the current name of the control key: "UserControl1". Because the control key is disabled, its icon should be dimmed in toolbox. After a few more steps, the control key should be allowed.

VISUALBASIC5.0 uses the same visual metaphor as establishing a generic application to establish an ActiveX control key. With this metaphor, you can first "draw" the interface, set some properties, write some event-driven code, and then you can get back on track.

Step 3: Draw a visual interface for the control key

Using controlcreationedition makes it easy to create a fine-tuning control because it can merge existing controls into a new, more specialized control key, in this case, a standard text box and a control key for a vertical scroll bar will be combined to create this fine tuning control.

Click the text box control key in the VisualBasic tool box, which is labeled 1 in the following illustration, with the mouse to draw a small textbox to the upper-left corner of the Project2 window.

Click the vertical scroll bar key in the tool box and draw it to the right of the text box control key.

Drag the control sizing handles around the newly drawn control keys to resize the control keys. This control sizing handle is awarded in the following figure to 3. You ctivex should be similar to the control key of the following figure.

Step 4: Write event-driven code

We have built a visual interface for a fine-tuning control. The next step should be to write event-driven code so that the text box displays the current value of the vertical scroll bar. The value of the text box should increase or decrease as the user drags the vertical scroll bar arrows up and down with the mouse. In order to tie the two events together, some code should be written in the change event of the vertical scroll bar. Double-click the vertical scroll bar to make the code window appear, knocking the following line of code into the window:

Text1.text=vscroll1.value

You might be amazed when you typed the code above. When typing "comma", VISUALBASIC5.0 will display a list of properties that the text box can have. An ActiveX build contains this type of information, and VisualBasic automatically makes it available immediately. This is an example of the new "smart" you will find in the visualbasic5.0controlcreationedition development environment.

When the code is all typed, close the Code window by clicking the Close box (number 1 in Figure 7). Finally, click the Close box (number 2 in Figure 7) of the Spinner Control key form to turn off the spinner Control key form.

Step 5: Use and control the built control keys

If the control key is successfully established and the spinner control form is turned off, the spinner control key should be allowed. Check to make sure it is not dimmed in the tool box window. Your environment should be similar to the one in the following picture.

The key to be tested is shown in Figure 8, number 1th.

To test the newly created Control key, first click it in the tool box and draw it in Form 1, as shown in the following illustration. Then press F5 to run the application. The value of the text box will change as you move the pointer up and down in the spinner Control key, which is consistent with the purpose of the program code we are compiling.

Congratulations, you just created your first ActiveX control key and wrote only one line of code.

Where are we going from here?

Next, you should look at some of the information located in http://www.microsoft.com/vbasic/controls/and learn more useful features that can easily be built into your ActiveX control keys. This information includes a property page that makes your keying data clear and understandable, and puts your control keys on a Web page without the need to use the Java programming language.

Once you've built a control key, you can put it into all the Microsoftactivex key hosts at once, and these hosts include:

Office97, VisualBasic4.0, visualc++, FrontPage2.0

If you are willing to put your ActiveX control keys on a Web page, you must use Activexcontrolpad. Activexcontrolpad is released as part of VISUALBASIC5.0 and controlcreationedition and can be downloaded free of charge from http://www.microsoft.com/workshop/author/cpad/.

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.