|
Correctly set scrollbars' width and height
|
Total Hit (3191) |
You should always modify a vertical scrollbar's width and a horizontal scrollbar's height to conform to the display resolution. You can learn the suggested size (in pixels) using the GetSystemMetrics API function, then convert it to twips, and rezise all the scrollbars on your forms accordingly. The
....Read More |
Rating
|
|
|
Create a owner form with API functions
|
Total Hit (2963) |
Starting with VB5, the Show method supports a second optional argument, that lets you specify which form owns the form that is about to be displayed:
«Code LangId=1»
Form2.Show , Me
«/Code»
A owned form is always displayed in front of its owner, and when the owner is unloaded, VB automatical
....Read More |
Rating
|
|
|
Create arrowed buttons without icons
|
Total Hit (3914) |
You don't need to use icons or bitmap to create buttons with arrows on them. In fact, you just have to select the "Windings" font, set a suitable font size (e.g. 12 or 14 points), and then enter one of these characters:
«Code LangId=1»
Line arrows
Chr$(223) Left Arrow
Chr$(224) Right Arrow
Chr
....Read More |
Rating
|
|
|
Create colorful Command Buttons
|
Total Hit (4151) |
The VB CommandButton control supports neither the ForeColor nor the BackColor properties. If you want to create colorful buttons without resorting to 3rd party controls, you can use an OptionButton control with the Style property set to 1-Graphical. Such OptionButton controls appear to be very simil
....Read More |
Rating
|
|
|
Create ListBox controls with companion priority buttons
|
Total Hit (2767) |
You can easily create a ListBox control similar to the one found in the VB's Project References dialog box, that lets you select multiple items and move them up and down using two companion buttons.
First of all, create a ListBox control (say, List1) and two CommandButton controls to its right, n
....Read More |
Rating
|
|
|
Create TextBox with dithered background
|
Total Hit (2082) |
If your video display has 256 colors or less and you assign a dithered color to the BackColor property of a TextBox control, you'll find that the background color under the text inside the TextBox is displayed in a different (solid) color.
To work around this issue, you must trap the WM_CTLCOLOR
....Read More |
Rating
|
|
|
Cut, copy, and paste using API functions
|
Total Hit (4642) |
Copying and pasting text and images programmatically isn't difficult at all, using the methods of the Clipboard object. However, implementing a generic Edit menu that copies and pastes the highlighted contents of whatever control is the selected control is often cumberson. For example, depending on
....Read More |
Rating
|
|
|
Detect whether a field on a form has been edited
|
Total Hit (1952) |
Many tip & trick collections report that you can learn if the contents of a text box has been modified by sending a EM_GETMODIFY message to the control. Actually, getting this information is much more simple. Just test the DataChange property: if non zero the field has been modified since the form w
....Read More |
Rating
|
|
|
Determine how a control got the focus
|
Total Hit (2337) |
At times it might be convenient to know how a given control got the focus, namely by means of the Tab key, an associated hotkey or a click of the mouse. You can learn this information through the GetKeyState API function, that returns the current state of a key. Here is a simple function that is mea
....Read More |
Rating
|
|
|
Determine maximum size and the position of a maximized form
|
Total Hit (2368) |
When the user resizes a form with the mouse or the keyboard, or maximizes it, Windows sends the form a WM_GETMINMAXINFO message, with lParam pointing to a MINMAXINFO structure that the form must fill with information about the minimum and maximum size that it is willing to be resized. Using a subcla
....Read More |
Rating
|
|
|
|
Determine when a ComboBox's area is being closed
|
Total Hit (2150) |
The ComboBox control exposes the DropDown event, that lets you determine when its list area is being opened. However, VB doesn't offer any simple way to understand when the list area is being closed. You can achieve this by intercepting the WM_COMMAND message that the ComboBox control sends to its c
....Read More |
Rating
|
|
|
Determine when a TextBox control is scrolled
|
Total Hit (1690) |
When the user scrolls the contents of a TextBox control - either by clicking on the companion scrollbars or by typing new characters in the edit area - the TextBox control sends its parent form a WM_COMMAND message, and passes its own hWnd property in lParam and the value EN_HSCROLL or EN_VSCROLL in
....Read More |
Rating
|
|
|
Determine whether a control has a scrollbar
|
Total Hit (2768) |
There is no built-in VB function that lets you know whether a control - such as a ListBox - is currently displaying a vertical scrollbar. Here's a pair of functions that check the control's style bits and return a Boolean that tells if a vertical or horizontal scrollbar is visible:
«Code LangId=1
....Read More |
Rating
|
|
|
Don't hard-code font names and size
|
Total Hit (1704) |
Unless you have good reason to do otherwise, you should always use standard fonts in your programs, because this ensures that your application will work on every Windows system.
If you want to use non-standard fonts, you should at least adopt the following guidelines:
«Code LangId=1»
Assign
....Read More |
Rating
|
|
|
Don't stop timers when a MsgBox is active
|
Total Hit (2071) |
Not all developers know that Timer controls in compiled VB5 and VB6 applications aren't stopped by MsgBox statement, so the Timer's Timer event procedure is regularly executed even when the message box is being displayed on the screen.
However, inside interpreted applications under all VB version
....Read More |
Rating
|
|
|
Don't use SetFocus on invisible controls
|
Total Hit (2033) |
In the Show event of a form you might be tempted to use SetFocus to select which field the end user should begin working with. However, this method raises an error 5 when applied on a control that is currently invisible.
If the logic of your application should give the focus always to the same c
....Read More |
Rating
|
|
|
|
Enable and Disable all or part of a scrollbar
|
Total Hit (3445) |
The new FlatScrollbar controls expose the ability to selectively disable their arrows. This is useful, for example, when the thumb indicator is at its minimum or maximum:
«Code LangId=1»
Private Sub FlatScrollBar1_Change()
If FlatScrollBar1.Value = FlatScrollBar1.Min Then
FlatScrol
....Read More |
Rating
|
|
|
Ensure that a form's TextBox and ComboBox controls have same height
|
Total Hit (3167) |
In general you don't have any control on a ComboBox's Height property, because it is determined automatically by VB depending on the font used for the ComboBox control. If you have a form that contains both TextBox and ComboBox controls, you should ensure that all your single-line TextBox controls a
....Read More |
Rating
|
|
|
Ensure that a TextBox caret is visible
|
Total Hit (3044) |
Setting a multiline TextBox's SelStart property doesn't ensure that the insertion point (the caret) is visible. You can achieve this by sending the control an appropriate message:
|
Rating
|
|
|
Extended user interface for combo boxes
|
Total Hit (2888) |
Apart from the different kind of combo boxes you can obtain by manipulating the Style property, another feature is made available by Windows when dealing with combo box controls, the so-called extended user interface. With standard combo box controls, the list portion stays invisible until the user
....Read More |
Rating
|
|
|
Get a reference to a form given its name
|
Total Hit (1920) |
In some cases you might want to activate a form given its name, but VB doesn't let you do it directly. However, it is easy to create a function that does it by iterating over all the forms in the current project:
|
Rating
|
|
|
Get the handle of the edit portion of a ComboBox
|
Total Hit (2942) |
The ComboBox control contains an invisible Edit window, which is used for the edit area. In most cases you don't need to access this inner control directly, but occasionally a direct control of that window can be useful. The first thing to do is get the handle of such inner Edit control, which you d
....Read More |
Rating
|
|
|
Hide and Show a control's scrollbars
|
Total Hit (3216) |
Most VB controls don't let you determine whether they should display a scrollbar or not. For example, a VB ListBox control displays a vertical scrollbar only when the number of its items is larger than the number of visible items. If you want to directly control individual scrollbars, you can use th
....Read More |
Rating
|
|
|
Highlight current word and line in a TextBox control
|
Total Hit (2987) |
Here's a simple way to highlight the current word in a TextBox control (i.e. the word where the caret is):
«Code LangId=1»
Text1.SetFocus
SendKeys "^{LEFT}+^{RIGHT}"
«/Code»
Similarly, you can highlight the current line in a multiline TextBox control as follows: «Code LangId=1»
Text1.SetFo
....Read More |
Rating
|
|
|
Highlight the contents of a control on entry
|
Total Hit (1786) |
Here's a simple way to highlight the current word in a TextBox control (i.e. the word where the caret is):
«Code LangId=1»
Text1.SetFocus
SendKeys "^{LEFT}+^{RIGHT}"
«/Code»
Similarly, you can highlight the current line in a multiline TextBox control as follows: «Code LangId=1»
Text1.SetFo
....Read More |
Rating
|
|
|
Implement a MaxLength property for the ComboBox control
|
Total Hit (2132) |
Unlike the TextBox control, the ComboBox control doesn't expose any MaxLength property, so you have no means of limiting the numbers of characters typed by the end user in the edit area. However you can set this value by sending a CB_LIMITTEXT message to the control, passing the maximum number of ch
....Read More |
Rating
|
|
|
Incremental searches within list boxes
|
Total Hit (2525) |
The DBList and DBCombo controls expose a MatchEntry property, that - when set to True - permits to perform quick incremental searches by simply typing the searched sequence of characters. If MatchEntry is set to False, any time the user presses a key, the next item that begins with that character be
....Read More |
Rating
|
|
|
Make a Checkbox control read-only
|
Total Hit (2945) |
By default, VB's CheckBox controls automatically toggle their Value property when the user clicks on them. This is usually the desired behavior, but at times you may want to be able to change their value only programmatically. Unfortunately, you can't achieve this result by simply setting the CheckB
....Read More |
Rating
|
|