http://www.developer.com/net/vb/article.php/1572321/Windows-Secrets-for-Visual-Basic-Part-1.htm
To call Visual Studio .NET "pretty cool" is getting a little clichéd. You know it. I know it. We've both created Web applications in minutes, figured out the
power behind the .NET Framework, and read how to create a Windows service without needing to
plug into the devilish delights of C++. As the Microsoft advertisement I read this morning quite rightly points out: It'll save you
thousands of development hours and position you far in front of your competitors. Unless, of
course, your competitors are also using Visual Studio .NET. Which is, in fact, extremely
likely. To stay ahead of the field you need to re-figure out all those nifty little secrets you
knew back in Visual Basic 6, getting back to the stage where you knew all those
nooks-and-cranny tricks that only time teaches. I'm talking about those nuggets of knowledge
that can save you even more time, and metamorphose you from an advanced user straight
through to pure .NET expert level. And that's just what I'm going to cover in this intriguing
series of twelve articles. Over the next five months, I'll be writing an article every two weeks, sharing a few of the
nuggets I'm compiling into my next book, VB.NET and ASP.NET Secrets. I'll be covering
top time-taught tricks for creating Windows, ASP.NET, database, and Web service
applications—and a little more, too. In this first article, we begin our three-part look at Windows applications, exploring a
few of the simpler gems that you just might not have tagged onto yet. We'll be looking at: And, don't forget, this is the simple beginning. Over the next eleven articles, you'll find
it all gets gloriously exciting. Ready to begin? You can give your Windows form a great transparent look by altering its Opacity
property. Set this anywhere between 0% (completely transparent) and 100% (regular opaque) to
see the windows underneath your application. If you haven't already noticed, someone stole the ToolTip property in .NET. If you want
little popup messages to appear when you hover your mouse over a button or whatever, you'll
need to figure out the ToolTip control. Here's how it works. First, you add an instance of the ToolTip control to your form. This
is an invisible component that actually displays the message. You can alter its properties
through the Property window, such as whether it is "Active" or the popup delay. Next, you need to add the actual ToolTip messages. Click on any of your controls and scroll
down to the "Misc" section (presuming you order your property list by category). You'll
see a property called something like "ToolTip on ToolTip1": This is a fresh property
your ToolTip instance gave every control on your form.
Simply set this property to your ToolTip message—and that's a wrap! When the user resizes your Windows form at runtime, by default all of your controls will
stay in place. They will not automatically resize with the form. You can change this behavior
by editing the Anchor property of a control. The Anchor property determines which sides of a form that control will stretch with.
After the default, the most common setting for this property is "Top, Bottom, Left,
Right"—meaning the control will stretch with all sides of your form, behaving like the
majority of resizable Windows applications. The Dock property of a control is also useful when positioning and resizing
controls. It allows you to dock a control to a particular side of a form and stick with that
side, regardless of how the form is resized. To set this, simply select a new region via the
Dock property drop-down. If you're looking to create the split panel look seen in many modern applications, you'll
be happy to learn that a new .NET Splitter control can help you achieve exactly that
effect. Here are the simple steps to recreating the split panel look in your own programs: And that's it! You can now try running your application. Your users will be able to "drag"
the Splitter and your two controls/panels will automatically resize. Develop an application in a program such as Microsoft Access and all your combo boxes will
incorporate "AutoComplete" by default, that ability to be able to tap a few characters in a
drop down and have the nearest matching selection picked out for you. In Visual Basic however, there's no such intrinsic support. If you want AutoComplete,
you've got to do it yourself. And this tip shows you how. Simply add the following methods to your form. The first is called AutoCompleteKeyUp
and accepts a combo box and KeyEventArgs object as arguments. You need to call these in
the KeyUp event of your combo box: it looks at what the user has typed and selects the
most appropriate match. The second is called AutoCompleteLeave and should be called
when the Leave event of your combo box is fired. This one simply takes whatever you've
finally chosen and cases it properly, as per the matching selection in the combo box. Let's look at those functions now: And here's how you may call these functions from your combo box: That's all you need to create your own AutoComplete combo boxes. And if you're feeling
really adventurous, you might even want to wrap all of this up into a neat little user
control. But we'll leave that for another tip... Command line parameters can be incredibly useful. They allow users or other applications to
pass startup information to your program. For example, if your program was called myapp.exe,
they might run the following: Here, we have one command line parameter, "/nodialogs". In VB6, we could read this using
the Command property. In VB.NET, this has been replaced with the
System.Environment.GetCommandLineArgs function, which returns an array of the passed
parameters. And here's a chunk of code to show you just how to read them: Coming up in part two of Windows Secrets, learn how to:
See you then! Karl Moore is a technology author living in Yorkshire, England. He runs his
own consultancy group, White Cliff Computing Ltd, and is author of two best-selling books
exposing the secrets behind Visual Basic .NET. When he's not writing for magazines, speaking
at conferences, or making embarrassing mistakes on live radio, Karl enjoys a complete lack of
a social life. You can visit Karl on the Web at www.karlmoore.com.
# # #
Windows Secrets for Visual Basic, Part 1
January 21, 2003
Introduction
The Secrets!
Making your Form Transparent
Who Stole the ToolTips?
Tricks of the Trade: Resizing Made Easy!
Creating Split Panels, Explorer-Style

Figure 1: Our Splitter control in actionSave User Time: Add AutoComplete to Combo Boxes
Public Sub AutoCompleteKeyUp(ByVal Combo
As ComboBox, _
ByVal e As KeyEventArgs)
Dim strTyped As String
Dim intFoundIndex As Integer
Dim objFoundItem As Object
Dim strFoundText As String
Dim strAppendText As String
' Ignore basic selection keys
Select Case e.KeyCode
Case Keys.Back, Keys.Left, Keys.Right, Keys.Up, _
Keys.Delete, Keys.Down, Keys.CapsLock
Return
End Select
' Find what user has typed in list
strTyped = Combo.Text
intFoundIndex = Combo.FindString(strTyped)
' If found...
If intFoundIndex >= 0 Then
' Get list item (actual type depends on whether data
bound)
objFoundItem = Combo.Items(intFoundIndex)
' Use control to resolve text - in case data bound
strFoundText = Combo.GetItemText(objFoundItem)
' Append the typed text to rest of the found string
' (text is set twice due to a combo box quirk:
' on certain platforms, setting just once ignores casing!)
strAppendText = strFoundText.Substring(strTyped.Length)
Combo.Text = strTyped & strAppendText
Combo.Text = strTyped & strAppendText
' Select the appended text
Combo.SelectionStart = strTyped.Length
Combo.SelectionLength = strAppendText.Length
End If
End Sub
Public Sub AutoCompleteLeave(ByVal Combo As ComboBox)
' Correct casing when leaving combo
Dim intFoundIndex As Integer
intFoundIndex = Combo.FindStringExact(Combo.Text)
Combo.SelectedIndex = -1
Combo.SelectedIndex = intFoundIndex
End Sub
Private Sub ComboBox1_KeyUp(ByVal
sender As Object, _
ByVal e As
System.Windows.Forms.KeyEventArgs) _
Handles ComboBox1.KeyUp
AutoCompleteKeyUp(ComboBox1, e)
End Sub
Private Sub ComboBox1_Leave(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles ComboBox1.Leave
AutoCompleteLeave(ComboBox1)
End Sub

Figure 2: Our AutoComplete combo box strutting its stuff.The Power of Command-Line Parameters
myapp.exe /nodialogs
Dim MyStartupArguments()As String,
intCount As Integer
MyStartupArguments = System.Environment.GetCommandLineArgs
For intCount = 0 To
UBound(MyStartupArguments)
MessageBox.Show(MyStartupArguments(intCount).ToString)
Next
Next Time...
About the Author