|
Create TextBox with dithered background
|
Total Hit (2085) |
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 (4651) |
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 (1958) |
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 (2343) |
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 (2369) |
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 (2154) |
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 (1692) |
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 (2777) |
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 (1709) |
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 (2076) |
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 (2037) |
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 (3454) |
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 (3181) |
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 (3051) |
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 (2897) |
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 (1925) |
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 (2947) |
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 (3226) |
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 (2990) |
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 (1791) |
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 (2136) |
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 (2531) |
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 (2951) |
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
|
|
|
Making a form appear as if it is disabled
|
Total Hit (2129) |
By changing the WS_CHILD style bit of a window, you can make it appear as if it is disabled, even if the form is fully active and functional. These are the statements you need:
|
Rating
|
|
|
Move focus with Up and Down keys
|
Total Hit (1785) |
In all standard controls, Up and Down arrow keys move the focus on the previous or next control in the TabIndex order, respectively. This contrasts with text boxes, where these keys move the caret on the adjacent character, which you can achieve in a more natural way using the Left and Right cursor
....Read More |
Rating
|
|
|
Mutually exclusive list boxes
|
Total Hit (2016) |
Many Windows programs use two adjacent list box controls to let the user select a number of items from a list of available values; such list boxes are mutually exclusive, in the sense that a given item always appear in the list box on the left (available items) or in the list box on the right (items
....Read More |
Rating
|
|
|
Open the list portion of a ComboBox control
|
Total Hit (2979) |
To programmatically open and close the list portion of a ComboBox control, all you need is sending the CB_SHOWDROPDOWN message to the control. Here is a routine that encapsulate the SendMessage API function:
«Code LangId=1»
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"
....Read More |
Rating
|
|
|
Optimized Paint procedures with subclassing
|
Total Hit (2503) |
The Paint event doesn't provide with information about which region of the form must be actually repainted, and therefore forces the programmer to repaint the entire client area, which in some cases can be a time-consuming operation.
You can determine the smallest rectangle that needs to be updat
....Read More |
Rating
|
|