Free Web Hosting Provider - Web Hosting - E-commerce - High Speed Internet - Free Web Page
Search the Web

    vbProgramming
Tutorials - Experimenting With Objects and Properties
 
       
vbProgramming Home :: vbProgramming Forums :: Tutorials :: Contact :: Links 
 
This tutorial will guide you through some of the objects that you see on the toolbar, and some properties and events. Basically the tutorial just shows you how to mess around with the your Form and make it look better.
 

 

 

Labels
Create a new project called Properties. Look at the toolbox. The first button on the toolbox you see is 'Pointer'. Don't worry about that, its default. It is basically your mouse. It just means that you aren't dragging anything onto the form.

The next button you see is 'Label'. If you have already been experimenting, you will notice that a label is used to guide your user though the form. Add a label to the form. Set the text property to "Type your comments here." Place it on the left side of your form.  Look through some of its properties. They include Name, Text, Height & Width (Size), Location, Font, ForeColor (which is the font's color), and BackColor. These are self-explanatory properties. Experiment with properties such as BorderStyle, Cursor, RightToLeft, Locked. TextAlign, and Image. After playing with those properties, you will begin to understand them.  One property that I mentioned is called Locked. This means that, you Lock the label in place so that you don't accidentally move it around.  Another property is called AutoSize. When you change the text value of a label, if AutoSize is set to True, then the label size will automatically increase according to how much text you put in there.

After labels come link labels. These labels are links! If you click on them, they will redirect you to somewhere else (another site, another location ,etc.)


Buttons
The next item you see is a button. The important properties are basically the same as labels. One important property for buttons is the Enabled property. Drag a button onto the form and set its enabled property to False. Name it MyButton and set the text to "Click Me". The user can't click on the button. Buttons are widely used in VB.NET. Let's look for some events for buttons. Go to your code(F7) or View | Code. Select MyButton from the list. Look at some of the events for it. Some of these self-explanatory events include:

BackColorChanged, BackgroundImageChanged, CursorChanged, Click, FontChanged, ForeColorChanged, KeyDown, KeyUp, KeyPress, MouseDown, MouseUp, and Resize.

For now, don't worry about KeyDown, KeyUp, KeyPress, MouseDown, and MouseUp.



TextBoxes
The next item you'll see is called a TextBox. Next to the label you created draw a TextBox. Set the text property to " " (When I say " " I mean blank). Set the name to MyTextBox.  Properties are similar to the one's you've seen already. Important properties for TextBoxes are MultiLine and WordWrap. MultiLine obviously make the textbox have more than 1 line! Word wrap makes the textbox's words to stay within its boundaries basically.  Look at the events. Go to your code and select MyTextBox. In the events you will find an important event for textboxes called TextChanged. This event executes when the text in the textbox changes! This event isn't really used in the present because what people do is,  they say: Enter a number in the TextBox and it will add itself by one. What people do is, they don't use the TextChanged event. They have a button that says something like "submit" and it adds it together. The TextChanged property is used in some rare situations. 

MainMenu
The next item on the list is called a main menu. Double-Click it and see what happens, a menu gets created. Now, notice below the form, there is a box that says, MainMenu1. Click somewhere else in the form, notice how the menu goes away? Well, click the box that says MainMenu1. Notice in the menu, written in gray, it says "Type Here." Well, type there. Notice how you can create another menu next to it by typing below it. An important feature for menus is the & symbol. Create a menu called &File. And create a menu called &New below it. Now run your program. Notice how the F in File is underlined and the N in New is underlined? Well, that's because you put an & before the F and the N. You may be asking, what is the use of the underlines? Run your program.  Type in this: Alt + F and Alt + N.  Its just another shortcut for "File" and "New." 

Note: If you are running Visual Studio 2002, there may be some errors with menu's. Sometimes, when you run your program your menu doesn't appear. All I can suggest to you is, close VS.NET and open it, or, create a new program and add the menu's in.

CheckBoxes and RadioButtons with GroupBoxes
The next 3 items on the list are: CheckBox, RadioButton, and a GroupBox. A CheckBox is really self explanatory. Create a label at the top of the form that says, "Choose your favorite Ice Cream Flavors." Make 3 CheckBoxes and set their text property to , "Chocolate", "Vanilla" and "Mint" and  name them accordingly (just name them to what their text is) Now create a  button that says "Submit" . Under that button's click event type this:

If Vanilla. Checked = True Then 
  
MessageBox.Show ("Vanilla is a good flavor") 
End
If

If Chocolate. Checked = True Then 
  
MessageBox.Show ("I like chocolate too!") 
End
If

If Mint. Checked = True Then 
  
MessageBox.Show ("Mint is nice") 
End
If

Basically it is self explanatory how it works! If Vanilla is checked, and you hit submit, it will display "Vanilla is a good flavor." Self Explanatory isn't it? If you check more than one, then it will show more than one message! If you wanted the user to select only one, then use RadioButtons. Drag and drop 3 RadioButtons onto the form. Delete the CheckBoxes. Use the same Names  (Vanilla, Chocolate, and Mint) and the sane Text properties (Vanilla, Chocolate, and Mint). Leave the code alone. Run your program. It is the same thing, except that you can only select one.

Create a label next to the label you made, and set the Text property to: "Choose your favorite colors." Draw 3 RadioButtons and set their Name and Text properties to: Red, Blue, and Green. Create another "Submit" button.  Under that button's click event type in this: 

If Red. Checked = True Then 
  
MessageBox.Show ("Red is a good color") 
End
If

If Blue. Checked = True Then 
  
MessageBox.Show ("I like blue too!") 
End
If

If Green. Checked = True Then 
  
MessageBox.Show ("Green is nice") 
End
If

 It does the same thing. Run your program. First select an Ice Cream and hit "Submit". Next select a Color and hit "Submit." You know what happens but look at your program!!! You can only select ONE RadioButton, even though one is Ice Cream and one is Color.  How would you be able to select 2 RadioButtons from different groups? 

The answer is, GroupBoxes.  Select and "Cut" (Ctrl + X or Right-Click | Cut) the RadioButtons from the Ice Cream group. Draw a GroupBox almost the same size the RadioButtons  in the Ice Cream group take up. Set the Text property of the GroupBox to "Ice Creams." Now, click once on the GroupBox and hit Paste (Ctrl + v or Right-Click | Paste). You cannot drag items into the GroupBox directly, so you have to either draw them into the GroupBox or if you already have existing items, you have to copy and paste them into the GroupBox.  Select the buttons, try to drag them out of the GroupBox. You can't because it is a container! Now, do the same thing for Colors. Run your program. You can now select one RadioButton from "Ice Creams" and one RadioButton from "Colors."

That's all for this tutorial. The other items on the ToolBox will be covered in other tutorials. 

The Source Code for this tutorial is located here:

You can also locate this by logging in to vbProgramming Forums and going to:
Tutorials > Tutorial Source Code > Source Code