Archive

Archive for January 18, 2009

Adding System Wide ‘Auto Complete’ to your Textbox/Combobox Controls in Visual Basic 2005.

January 18, 2009 programmervb 1 comment

As you will see, adding Auto Complete support to textbox and combobox controls has NEVER been easier than it is now in Visual Basic.NET 2005. No longer do you HAVE to use the Windows API’s to get the Auto Complete functionality.

I will assume you already have a ‘Windows Application’ based project open. You can go ahead and add a textbox control or combobox control to the form. Select the textbox and goto the properties window. (I will assume you added a textbox, but the process is the same for a combobox also. I will just refer to textbox instead of combobox.)

There are 3x properties that relate to the ‘Auto Complete’ feature. You have “AutoCompleteCustomSource”, “AutoCompleteMode” and “AutoCompleteSource”. AutoCompleteCustomSource is exactly how it sounds. You can have your own text that you want the user to be able to use when they are typing in the control. But, I am not interested in going over that property right now though. There is really nothing more to it than what I already said. :)

OK, the “AutoCompleteMode” property is simply how the AutoComplete text responds. Click on the “AutoCompleteMode” property and then open the dropDown list associated with it. You will see 4x ‘modes’ available. “None, “Suggest”, “Append”, and “SuggestAppend”. This property MUST be selected either “Append”, “Suggest”, or “SuggestAppend” for the AutoComplete feature to work. If you select “Suggest” mode, then ‘AutoComplete’ will display a list that matches the text that has been typed thus far that you can scroll through and choose from. If you select “Append” mode, then as you are typing, it will automatically highlight the closest match to the text thus far in the textbox/combobox control, usually in alphabetical order. Plus, while you are typing, you CAN use the ‘Up/Down’ buttons on the keyboard to scroll through the list of text that is similar to the text that was typed in the textbox control. The “SuggestAppend” mode, is of course the combination of the other 2x modes. As you are typing the text, it will highlight the first occurance of matching text while also displaying a list of all the text that matches what has been typed in the control.

The “AutoCompleteSource” property is exactly how it sounds. It is the location on the computer system to get the ‘AutoComplete’ list from. Click on that property and then click on the box to dropdown the enumerator values that are available as the source. Available values, at least on my computer are: “FileSystem”, “HistoryList”, “RecentlyUsedList”, “AllUrl”, “AllSystemSources”, “FileSystemDirectories”, “CustomSource”. Just like the “AutoCompleteMode” property, you MUST select one of these values for you to get ‘AutoComplete’ functionality. Since all of the values are self-explanatory, I will not go over them.

Just to test out the ‘AutoComplete’ feature. With a textbox control, (Or Combobox), click on the “AutoCompleteMode” property and select the “Suggest” mode. Then click on the “AutoCompleteSource” property and then select “AllUrl” as the source. Run the project, start typing in the textbox ‘www’ and you should see a list of url’s you’ve visited that start with ‘www’ popup. You can then click on one of the urls and it will put that url text in the textbox.

And thats ALL there is to it! Enjoy!

Categories: VBNet

Adding Custom Tooltips – Visual Basic .NET 2002/2003

January 18, 2009 programmervb 3 comments

In Visual Basic 6.0 we had a property for tooltip balloons. All you needed to do was type in the text you wanted to display. But you didn’t really have much control over the toolTips in general. In Visual Basic.NET, that simple feature appears to have been removed by default. That doesn’t mean we still can’t have tooltips. Below you will see just how simple it is to implement this feature and control how your tooltips will react. You have more “say” in what goes on with your tooltips. For Example, you can now set the length of time the pointer must remain stationary within the tooptip region before the balloon will appear.

To get started, start a project. In your ToolBox look for a ToolTip component. If you do not see one, then right click inside your toolbox and select “Customize Toolbox”. Click the ”.Net Frameworks Componets” tab, scroll down till you find “ToolTip” then check the box and press OK. You should now see a ToolTip component available. Double click the ToolTip to add it to your project. I re-named mine toolTip. If you look at the properties available for the ToolTip you will see: Automatic Delay, Initial Delay, and such that are available. I will not go over any of these settings since they are pretty much self-explanatory. Go ahead and add a button to the form. I named mine btn. In the btn_MouseHover event put:

toolTip.SetToolTip(btn, “Hello, This is just a simple test….”)

Start your project and place your mouse pointer within the button region and let it sit idle for a few seconds. You should then see the ToolTip balloon popup with the text you specified. You can also goto the ‘btn’ Button control property, you will see a property named: “Tooltip on tooltip”. You can put the text you want displayed and it will use your ToolTip settings without having to execute the toolTip yourself. As you can see, it is very easy to add support for ToolTips.

Categories: VBNet