|
Don’t use the GotFocus and LostFocus events
|
Total Hit (4561) |
Have you ever tried to change the BorderStyle, HideSelection, MultiLine, ScrollBars, WordWrap and TextAlign properties of a TextBox, or the ComboBox’s RightToLeft property from inside the control’s GotFocus or LostFocus events? You’ll get a System.ComponentModel.Win32Exception exception saying "Erro
....Read More |
Rating
|
|
|
Hiding pages of a TabControl
|
Total Hit (2861) |
Sometimes you may need to hide or show some pages of a TabControl according to the information you want to show, basing on the currently logged-in user for example (users with low privileges won't be able to get all the information or to change records). To do this, you may attempt to add or remove
....Read More |
Rating
|
|
|
|
Map an enumerated value to a set of OptionButton controls
|
Total Hit (2646) |
In VB6 and previous version, displaying an enumerated value in a group of option buttons is quite simple, provided that the option buttons be grouped in a control array. VB.NET doesn't support control arrays, so you can't reuse the same simple coding techniques. However, you can prepare a couple of
....Read More |
Rating
|
|
|
|
Skipping columns when tabbing on a DataGrid
|
Total Hit (3681) |
It happens quite often that you have a DataGrid with hidden columns (with width = 0), because you need their values but don't want to show them to the user. However, when you tab through the DataGrid's columns, these "hidden" columns are still taken into account in the tab order. This means that whe
....Read More |
Rating
|
|
|
Using multiple fields as value for the DropDownList control's items
|
Total Hit (4208) |
Being an avid Access Programmer I have been frustrated with the limitation of VB DropDownLists to using only 1 field as the value. I found a way to simulate/work around this behavior with concatenation of several database fields at the query level to be my columns(i.e. Select KeyId1 + '~' + KeyId2 +
....Read More |
Rating
|
|
|
A simple way to control a common dialog's position
|
Total Hit (4198) |
The CommonDialog control doesn't provide any direct way to decide where a common dialog appears on the screen. In all cases, in fact, the control tries to display the common dialog centered on its owner form. This behavior suggests a simple way to affect the approximate position of the common dialog
....Read More |
Rating
|
|
|
Changing the current record using bookmarks
|
Total Hit (2485) |
If you try to use a DataList and some labels or text boxes linked to an ADO Data control, and you click on some items in the list, you'll notice that the data in the labels won't change, because the current record isn't changed.
To have the code work correctly, you have to write code in the Clic
....Read More |
Rating
|
|
|
Clear a MaskEditBox control without raising error
|
Total Hit (3125) |
You can't clear the contents of a MaskEdBox control by setting the Text property to a null string if the MaskEdBox's Mask property contains delimiter. In fact, you must include those separators in the value you assign to the Text property, otherwise you get Error 380 - Invalid property value.
A s
....Read More |
Rating
|
|
|
Copy the contents of the WebBrowser control to the Clipboard
|
Total Hit (7566) |
To programmatically copy text from the WebBrowser control you can use its ExecWB method, to which you must pass the OLECMDID_COPY constant as its first argument.
WebBrowser1.ExecWB OLECMDID_COPY, OLECMDEXECOPT_DODEFAULT
You can also select the entire WebBrowser's contents by invoking the Exec
....Read More |
Rating
|
|
|
Download and save an HTML page with the Internet Transfer control
|
Total Hit (2889) |
You can easily download an HTML page by using the Internet Transfer Control (INet). Here's a reusable routine that uses this control to download the HTML page at the specified URL and optionally save it to a local file. In either case the routine returns the contents of the page as a string:
«Co
....Read More |
Rating
|
|
|
Download and save an HTML page with the Internet Transfer control
|
Total Hit (2891) |
You can easily download an HTML page by using the Internet Transfer Control (INet). Here's a reusable routine that uses this control to download the HTML page at the specified URL and optionally save it to a local file. In either case the routine returns the contents of the page as a string:
«Code
....Read More |
Rating
|
|
|
|
Insert a picture into a RichTextBox control
|
Total Hit (4045) |
Here's a simple method to programmatically insert an image into a RichTextBox control, by copying it into the clipboard and then pasting it into the control:
«Code LangId=1»
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal _
hwnd As Long, ByVal wMsg As Long, By
....Read More |
Rating
|
|
|
Let the user add tab characters to a RichTextBox control
|
Total Hit (3078) |
Here's a simple method to programmatically insert an image into a RichTextBox control, by copying it into the clipboard and then pasting it into the control:
«Code LangId=1»
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal _
hwnd As Long, ByVal wMsg As Long, ByV
....Read More |
Rating
|
|
|
Print the WebBrowser's contents
|
Total Hit (3061) |
The WebBrowser control doesn't expose any method to directly print its contents. You can achieve this effect through the ExecWB method, by passing the OLECMDID_PRINT constant in its first argument:
«Code LangId=1»
' display the Print dialog
WebBrowser1.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_PROMP
....Read More |
Rating
|
|
|
Print the WebBrowser's contents
|
Total Hit (2873) |
The WebBrowser control doesn't expose any method to directly print its contents. You can achieve this effect through the ExecWB method, by passing the OLECMDID_PRINT constant in its first argument:
' display the Print dialog
WebBrowser1.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_PROMPTUSER
You can
....Read More |
Rating
|
|
|
|
Get full control on the text typed in a ListView's item
|
Total Hit (3516) |
The ListView control exposes the AfterLabelEdit event to let the programmer validate the text entered in a ListItem, but there is no way to trap keys as they are typed by the user. This prevents you from discarding unwanted characters while the user types them.
You can work around this problem by
....Read More |
Rating
|
|
|
Get full control on the text typed in a TreeView's node
|
Total Hit (3775) |
The TreeView control exposes the AfterLabelEdit event to let the programmer validate the text entered in a Node, but there is no way to trap keys as they are typed by the user. This prevents you from discarding unwanted characters while the user types them.
You can work around this problem by sub
....Read More |
Rating
|
|
|
Get or Set the height of TreeView nodes
|
Total Hit (3947) |
In plain VB there is no way to determine or change the height of node elements in a TreeView control. All you need to accomplish both tasks, however, is send the right message to the control.
«Code LangId=1»
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal _
hW
....Read More |
Rating
|
|
|
How to apply the flat style to a toolbar
|
Total Hit (2732) |
All recent Windows applications use a flat toolbar similar to Internet Explorer 's and Microsoft Word's ones. Visual Basic 6 includes a Toolbar control that supports the flat look, but if you are still using VB4 or VB5 and you want to use a flat toolbar without buying a new ActiveX control, you just
....Read More |
Rating
|
|
|
Let the user insert OLE objects in a RichTextBox control
|
Total Hit (2619) |
A little-known feature of the RichTextBox control allows you to insert an OLE object in the text being edited. However, you can do so only programmatically, by adding an element to the OleObjects collection. An easy way to let the user select the object to be embedded in the control is using the Ins
....Read More |
Rating
|
|
|
Limit the length of an item in a ListView control
|
Total Hit (3810) |
The ListView control doesn't expose any property that lets you limit the amount of text users can type when editing an item's label. However, you can do the trick with a couple of SendMessage API calls from within the BeforeLabelEdit event: with the LVM_GETEDITCONTROL message you retrieve the handle
....Read More |
Rating
|
|
|
Limit the length of the text in a TreeView node
|
Total Hit (4412) |
The TreeView control doesn't expose any property that lets you limit the amount of text users can type when editing a Node's label. However, you can do the trick with a couple of SendMessage API calls from within the BeforeLabelEdit event: with the TVM_GETEDITCONTROL message you retrieve the handle
....Read More |
Rating
|
|
|
Load items faster in the TreeView and ListView controls
|
Total Hit (2657) |
There is an easy, but under-utilized, technique for loading many nodes in a TreeView control (or ListItems in a ListView control) that is faster than the standard technique. Consider this loop:
«Code LangId=1»
For i = 1 To 5000
TreeView1.Nodes.Add , , , "Node " & i
Next
«/Code»
Instea
....Read More |
Rating
|
|
|
Prevent dragging elements in a ListView control
|
Total Hit (3196) |
The ListView control doesn't expose any property that lets you disable the dragging of its elements. To do so, you must trap the WM_NOTIFY message that the ListView control sends its parent form when the drag operation begins, and "eat" it. Using the MSGHOOK.DLL subclassing library it's easy to acco
....Read More |
Rating
|
|
|
Selecting an entire row in a ListView
|
Total Hit (3745) |
The ListView control that comes with VB6 lets you select an entire row by setting its FullRowSelect property to True. If you are working with VB5 or you're using VB6 with the old version of the Microsoft Windows Controls this capability isn't avaible, but if you have installed the comctl32.dll versi
....Read More |
Rating
|
|
|
Suppress TreeView's tooltips
|
Total Hit (3567) |
By default, all TreeView controls whose version number is 4.70 or higher display the text of the node under the cursor if the node itself isn't completely visible. You can turn off and on this feature by resetting a bit in the control's style, using the following code:
«Code LangId=1»
Private
....Read More |
Rating
|
|