Visual Basic Tutorial - Part 2, Page 3
Using more built in VB controls.
Image - - This control allows you to display a picture on your Form. Perhaps an image of yourself, the supercool programmer! Or maybe your cat. Or dog. Or a rare elephant from the invisible forests of Outer Mongolia. Or whatever. Try playing with the Picture and Stetch properties
Label - - You often use this control to display information to the user, such as an explanation of what they should do. Try playing with the Caption and Font properties
TextBox - - The TextBox control is a little like McDonalds; common, usually trouble-free and definitely overused. You often utilise this control to collect information from the user or display data from a database. Try playing with the Alignment, BorderStyle, Font, MaxLength, MultiLine, PasswordChars, ScrollBars, ToolTipText, Text and Visible properties
CommandButton - - This is a pretty boring yet very common control. As Black Adder would say, "It's about as exciting as getting an arrow through the neck then realising there's a gas bill attached". It simply creates a button the user may click to run a slot of code. Try playing with the Cancel, Caption and Default properties
DriveListBox - - Whilst this control doesn't have many properties you can fiddle with, it's great to observe. You've seen this famous drop-down list many times before and now it can be incorporated into your own cool program! Try playing with the related DirListBox and FileListBox controls
Shape - - This control draws a shape on your Form. Hmm, not very exciting but try playing with the Shape, FillStyle and FillColor properties for a wild time. Oh yes.
Yikey, what a list! Don't worry about remembering them all, just observe the description of each property just below your Properties window - and test them by running the application, or "project".
Don't forget how to run an application:
- Press F5 (or click the button)
When designing an application, remember that you're an artist. The Form is your canvas and the controls, your paints. Just throw them all together and hope for a Van Cough, like my own:
Hmm, well OK, it won't win any (major) design awards but it only took me about three seconds. In fact the results of my application design exam were so low they were last spotted by Alice in Wonderland shortly after she pondered, "I wonder what's down that hole?"
What's that? You really don't care? Oh, no problem. We'll save reader-writer bonding for later.
Before you skip the rest of this section, I have a few final words of gizdom. Every single control you add to a Form has a Name property - it should appear at the very top of the Properties window.
Every time you add a control, an automatic name is assigned - such as Command1. That's not very neat and professional geeks get pretty upset if you don't bother following their little rules.
So, let's try to keep them happy. Every time you add a control (I know, I know... it's a hassle!) rename it with a more English address. For instance, if you have a Text Box that will hold a date, call it "Date".
But hold on. It gets worse. The Visual Basic community also have their own "naming conventions" where, for instance, Text Box names are preceded by "txt".
Therefore if you had a Text Box that will hold a date, it's advisable to change its name to "txtDate". Other prefixes include:
ComboBox - cbo (eg cboProductCodes)
CommandButton - cmd (eg cmdOK)
Form - frm (eg frmOrders)
CheckBox - chk (eg chkExtraCheese)
OptionButton - opt (eg optPlanTwo)
That'll do. Even I can't remember them all!
Top Tip: You can find a list of more naming conventions than you can wave a very large stick at here.
It's advisable to keep names pretty unique. There are circumstances when you may want more than one control with the same name, but we'll save that for another tutorial. Right now, stick to one name per control.
During the next section, we'll see how this name allows us to control a control programmatically! Try saying that at 3am on a Friday night. After four pints of Guinness. And an extra spicy burn-your-mouth-out curry.
Top Tip: Be sure to check the Controls.vbp sample that ships with the more recent versions of Visual Basic. This demonstrates the neat features of most standard controls. You might also be interested in John Percival's article on how to design your application - particularly the section on Tab Order.