Article Options
Premium Sponsor
Premium Sponsor

 »  Home  »  .NET Newbie  »  Simple Steps in VB.NET. Part 3 - Address Book 2
Simple Steps in VB.NET. Part 3 - Address Book 2
by George Poth | Published  06/05/2003 | .NET Newbie | Rating:
George Poth

I have been teaching English in Brazil since 1994 and always wanted to do more for learners than common textbooks can offer. This started with web sites that couldn't reach most students as computers and the Internet are not standard for most people in this country.

Computer tools to help Brazilian students learn a complex language like English are practically non-existent and so I sent some suggestions to software companies. Since Brazil is neither a target market for English textbooks nor for software of this kind, the rejection seemed natural.

As a result, I tried some free developer tools such as Borland's free C++ compiler, Free Pascal, and Envelope's Visual Basic. Envelope's Visual Basic, which is a Microsoft Visual Basic 1.0 clone and still available, suited my taste but I knew it was obsolete technology. In March 2003, I bought a copy of Microsoft Visual Basic .NET Standard and have been hopelessly contaminated with the programming virus ever since.

I mostly write programs for educational purposes. Having discovered the wonderful world of DirectX recently, I am diving into the most entertaining part of programming: games. One can connect teaching with pure entertainment, learning, and culture.

 

View all articles by George Poth...
Simple Steps in VB.NET. Part 3 - Address Book 2

Article source code: ssteps3_addressbook2.zip

The address book we started in Part 2 is already fully functional, but some things should be improved. Run the program and press the tab-key several times while observing the textboxes and the buttons. You will see that each time you press that key another textbox or button gets the focus. When a textbox is focused, a user can type into it without clicking it. When a button is focused, a user could simply press Enter to execute the action for which the button was made. Our tab-key works, but not quite as a user would expect it. That's why we are going to make some changes.

We have made the ID-textbox read-only. A user can't modify the content, so why would he/she go there using the tab-key? Think sharp! And if you ever get the answer, let me know. Since I can't think of a good reason, I will simply disable the tab-key for this item. To do so, go to the properties window and set the tab-stop property to false. The ID-textbox will be ignored from now on when you press the tab-key in the running program.

The tab-key should work with all other textboxes because the user is supposed to enter data. We have to rearrange the tab-indexes so that each time you press the tab-key, the next textbox gets the focus. You can change the tab-index number in the properties window, right above the tab-stop property. Change the numbers as shown in the table. Make sure you click each item before you try to change things.

Tab-Stop NumberItem
0editName
1editSurname
2editStreetAddress
3editZipCode
4editState
5editPhoneNumber
6editEmail

The tab-key also works with the buttons. For the sake of simplicity, disable the tab-key for all the buttons. It works the same way as you did with the ID-textbox. Don't think I'm sloppy. Many of you might think that setting the tab-key for the buttons is very simple, but believe me, it's not. They can be very useful when planned carefully. They can also easily become a pain in the - aw, I'm sure you know where - when you just put them there to show off. It would take more time to go into this, so let's have that in a later article. When you're done with the tab-indexes, run your program and see that it has improved a lot with these simple changes.

Speaking of changes, all programs have an icon, and ours? Yuh, okay, we have that blue-blah-blah standard application icon, and we have that primary-color-I-wish-you-weren't-there-anymore standard icon in the title bar. For those who like changes, I have included a different icon in the bin folder of the program. The icon comes from a web and lets us use it for non-commercial purposes. Sorry, but I won't advertise this web here because that's not my job.

To change the icon in the title bar, go to the properties window and find the property "Icon". Click the icon once so that the ellipsis appears. Then click the ellipsis and browse for your icon. Finally, click the icon. Wow, it's changed!

The application icon is the icon that would appear in the users menu if you installed the program on a computer. Changing the blue-blah-blah application icon is equally easy. In the Solution Explorer, right-click Addresses and choose Properties. In the Addresses Property Pages window, click Build in the left pane. You will see our old friend in the window, the blue-blah-blah application icon. Click the ellipsis on the left, next to the drop-down box which reads Default Icon. Browse for your icon as you did before and click it. You must build your program before you can see the change. When you have built it, open the folder of your program, the Debug folder, and see that the standard application icon has gone.

In Part 1 (The Button), we used tool tips, remember? Tool tips are those small yellow messages that pop up when the mouse goes over an item. Let's use them again. Just repeating what we've already learned would be dull, wouldn't it? How about multiple-line tool tips?

From the toolbox, insert tool tips. I hope you remember how that works. If you don't, feel free to review that part. It's not necessary to rename this item because we have only one. My habit is - I know, I have a lot of them - to rename everything to something very, very short, but it must remain easy to identify. I renamed my tool tips from ToolTip1 to msg. Why? I'm very, very lazy. I believe it's easier to type "msg" in each line than "ToolTip1".

Before you start writing your tool tips, you should change the property AutoPopDelay. Change the value from 5000 to 15000. This will display our tool tips for fifteen seconds instead of only five. You won't believe it: most programmers don't even bother to check this item although they have fifteen lines - or more - of tool tips. So after five seconds you're supposed to have read those fifteen lines. Ah, yes, and always check your text for spelling mistakes; they can make a horrible impression on some users.

Make sure you write each tool tip as one line. The code you see displayed here must fit the page, so it's impossible to reproduce it as it should actually look in your code. If you're in doubt, have a look at my updated sample. In part 1, I have intentionally not used multiple-line tool tips because these require more attention from you. It's very easy to get an error due to something as simple as an empty space. Observe these empty spaces when you write the code.

Private Sub DataForm1_Load(ByVal sender As System.Object_
    ByVal e As System.EventArgsHandles MyBase.Load

    'textbox tooltips:
    msg.SetToolTip(editID_
        "This number is generated automatically." & _
        Microsoft.VisualBasic.ControlChars.CrLf & "You can't change the " _
        & "input.")
    msg.SetToolTip(editName"Type the person's first and middle name here.")
    msg.SetToolTip(editSurname"Type the person's family name here.")
    msg.SetToolTip(editStreetAddress"Type the street address