Make a Property Page
Now the developer can click on the ellipsis next to the Custom property for your control to see the property pages.
- Create a new ActiveX control project. Give the control properties.
- Invoke the Project menu's Add Property Page command. It is set to a standard size so don't resize it.
- On the property page:
- Add controls to let the user view and modify the properties.
- Create Boolean variables to indicate when the user changes each value.
- In the PropertyPage_SelectionChanged event handler, set the values of the controls on the property page using the property values from the selected controls in the application. Set the property Booleans to False and set Changed to False.
- When the user changes a property value, set its Boolean to True and set Changed to True.
- In the PropertyPage_ApplyChanges event handler, see which properties have been changed and set those values for the selected controls.
- Connect the property page:
- Open the control's form window.
- In the Properties window, click on the Property Pages entry. Then double click the ellipsis (...) to the right.
- Check the box next to your property page and click Ok.
Click here to download an example program.
Use the Forms ComboBox
(By Ganesh R)
The traditional combo box on typing a character doesn't lists the matching values
in the combo box. For this purpose we can use Microsoft Forms 2.0 Library under references.
This combo box is a very good one where in on typing a single character the first matching
value is selected and on selecting the second the next closer matching value is displayed
and so on.
Aykut Cantürk points out:
Microsoft does not recommend the usage of this library. It differs from Office version to version, language to language. As a result, the installation process can damage office applications. This is an experimental knowledge and not accepted by Microsoft.
Giving a Control an About Dialog
When you place an ActiveX control on a form, you can click on the
ellipsis to the right of the About entry in the control's Properies
window to see information about the control. Here's how to add this
to your ActiveX controls.
Now you are ready to go. When you click the ellipsis next to About in
the control's Properties window, the development environment calls your
- Create the dialogs form.
- Create a ShowAbout subroutine in the control that displays the
- Select the control's project in the Project Group window and open the
Tools menu's Procedure Attributes command.
- In the Name combo box, select ShowAbout.
- Click the Advanced button.
- In the Procedure ID box, select "About Box."
- Click the Ok button.
My book Custom Controls Library shows how to do a lot of other ActiveX
control stuff and includes the complete source code for 101 ready-to-run ActiveX controls.
Reduce Media Player Control Flicker
(By Luis Ferro)
To use the media player (in Windows NT) one have to be sure that the avi has at least 5
seconds of frames or some flicker and black frames will appear on
screen. The media player has also some strange behaviors about what
should be shown or not. One must make sure that if the controls are not
visible, then the control itself must be visible. To make the control
"disapear" just change the top to out of the screen image. Otherwise
some phantom controls and sliders will surface somewhere on the screen.
Upgrading a Control
(By Jake Lake)
After editting a control, re-OCXing it, loading the project and an error occurs do this:
- Load the whole project
- Say "yes" and "ok" to the messages that refer to continuing to load process
- Second-Click on the side tool-bar and re-load you upgraded control.
- Click Open from the file menu
- When it asks you to save your project, ONLY save the .vbp files, ONLY!
- When it asks you to load, re-load you project and your control should be upgraded!!!
Disabling Picture Previews
(By Daniel Fabian)
Daniel wanted to load Web pages with the Web Browser control without loading pictures. With a little digging, he found that whether the pictures are loaded is controlled by the registry setting (all on one line):
Unfortunately this is the same key used by Internet Explorer so if the control doesn't load pictures, neither does IE.
When you change versions of a control, particularly ActiveX controls
you are building, old projects may be unable to corrcetly load the
control. When you load the project, Visual Basic replaces the control
with a PictureBox having the control's name.
You can delete the PictureBoxes and replace them with new controls.
If you have a lot of controls, that is a hassle.
Another solution is to open the project in a text editor and correct
the control's version number. If the program does not use any features
no longer supported by the control, it should work.
(By Bill Meister)
I found that populating the MSHFlexgrid control can be incredibly slow compared to populating the older MSFlexgrid control.
If you do not need to use the hierarchical properties of the MSHFlexgrid then definitely use the MSFlexgrid..
In a recent application that I wrote to fill a large grid from a complex SQL call, I initially used the new MSHFlexgrid control and
populated it for the user to view. The populating and updating of the grid took over 45 seconds. Just switching to the older MSFlexgrid
control knocked down this to less than 15 seconds. This improvement made the wait just bearable!
[I have also noticed that you can speed the control up if you set Visible = False when you begin the update and then Visible = True when you are finished. The control doesn't actually go away in between, it just doesn't update every time you change a cell's value. -- Rod]
Disable All Controls On A Form
(By Theodore Fattaleh)
' Be careful using this option because if you
' have a code that says "Call Commad1_click"
' then it will not fire.
Dim i As Integer
For i = 0 To Form1.Controls.Count - 1
Form1.Controls(i).Enabled = False
Display a Picture in a Status Bar
Right click on the Status Bar control and select the Properties command. Click the Panels tab. Add a new panel. In the Picture area, click the Browse area and select the picture you want displayed in that panel.
Load a Blank Page in WebBrower Control
When you run a program that contains a WebBrower Control, by default it comes up invisibly. That can make the program look rather strange.
To make the WebBrowser appear and look empty but normal, execute this code when the form loads:
Private Sub Form_Load()
Creating an ActiveX Control
Creating an ActiveX control that does something useful is a bit too complicated to describe here, but the basics are simple. Start a new project. Select the ActiveX Control option from the new project dialog.
Give the control a meaningful name. If you call the control MyControl, then when the developer creates instances of the control, they will be named MyControl1, MyControl2, etc.
Give the control public properties and methods to let the developer control it. The ActiveX Control Interface Wizard can help with some of this.
Set the control's ToolboxBitmap property to the bitmap you want to display in the developer's toolbox. This bitmap should be 16 pixels wide and 15 tall. If it is not, Visual Basic will stretch it to fit. That usually produces an ugly result.
When you have given the control the properties and methods it needs, select the Project menu's Properties command at the bottom. Enter a meaningful project name and description on the General tab. On the Make tab, you can also enter the company name, copyright information, etc.
Now you are ready to build the OCX file. Select the File menu's Make Project_Name.ocx command. That's all there is to it.
To use the control, create a new Standard EXE project. Select the Project menu's Components command. In the dialog, find the new control. It will be listed using the description for the project that you entered in the project properties General tab.
When you click Ok, you should see the control's bitmap in the toolbar. You can now use the control just like any other.
There is a LOT more to say about ActiveX controls. For more information, look in my book Custom Controls Library. In addition to giving more information on control creation in general, this book shows how to build 101 useful custom controls. Complete source code is included on the CD-ROM. For more information including readers' comments and a table of contents, click here.
See Which Items Are Selected
When multiple selection is allowed in a ListBox, use a loop to see if the Selected property is true for each item.
Dim i As Integer
For i = 0 To List1.ListCount - 1
If List1.Selected(i) Then
MsgBox List1.List(i) & " is selected."
To make a TextBox automatically select its text when focus enters it, give it a GotFocus event handler like this:
Private Sub Text1_GotFocus()
Or use SelStart and SelLength:
Private Sub Text1_GotFocus()
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
The CommonDialog control's Filter property lists text strings alternating with filters separated by pipe | symbols. For example:
CommonDialog1.Filter = _
"Bitmap Files (*.bmp)|*.bmp|All Files (*.*)|*.*"
Here there are two filters. The first displays the string "Bitmap Files (*.bmp)" to the user. When the user selects the filter, the dialog applies the filter "*.bmp" The second filter displays "All Files (*.*)" and applies "*.*"
You can make a TextBox scroll to the bottom with:
Text1.SelStart = Len(Text1.Text)
Learn Control Array Bounds
You can use a control array's UBound and LBound properties to determine how many controls are loaded. For example, the following code fills a string with the captions in the Label1 control array.
For i = Label1.LBound To Label1.UBound
txt = txt & Label1(i).Caption & ", "
Make Return Act Like Tab
Set the form's KeyPreview property to true. In the form's KeyPress event handler, check for the carriage return. If you get one, use SendKeys to generate a TAB instead. Set KeyAscii to 0 so the carriage return is discarded.
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
KeyAscii = 0
Use Pictures on CommandButtons
To use a picture on a CommandButton, you must set its Picture property. You must also set its Style to 1 - Graphical. If you do not, the picture is ignored.
Send your Tips and Tricks to firstname.lastname@example.org.