VB.NET Uncovered: Big Changes, Page 2
Windows Forms are essentially a more advanced version of forms as we know them today. And they bundle with a load of pretty cool functionality that enable you to build some darn advanced screens.
Top Tip: The name 'Windows Forms' may change by Beta Two. Microsoft haven't yet fully decided on a name. They originally christened this baby 'WinForms', then realised they'd be breaching some serious trademark turf. So, it's still in the air - prepare for change.Again.
Well, instead of boring you with a technology thesis, let's jump straight in and explore Windows Forms...
- Launch VB.NET
- On your Start Page, click 'Create New Project'
- Under 'Visual Basic Projects', select 'Windows Application'
- Change the Name and Location, if required
- Hit the OK button
Hurrah - You're looking at a Windows Form!
Top Tip: Look at the Solution Explorer. See how the form filename is Form1.vb? All Visual Basic code - whether we're talking about forms or class modules - are stored as .vb files. The code inside that file describes what it is and does.
Now, click on Form1 and have a quick scroll through the Properties window. Ohhh, a few changes there. The Caption property is now known as Text. The Font property is broken down into Name, Size and such (hurrah!). Oh, and there's an IsMDIContainer property for building MDI apps.
Top Tip: .Caption properties have gone inVB.NET. You'll find they've all been standardised to .Text. You'll also findthat .Tag properties have disappeared.
Turn your eye to the Toolbox on the left of your screen. Click the 'Win Forms' box and stare in amazement. Well, maybe. Yes, these are all the new control toys you get to play with in VB.NET!
Scroll down that list using the down arrow near the bottom of the Toolbox. You'll find more 'intrinsic' controls than ever before. Let's meet a few.
Add a Label to Form1, the same way you would in VB6
Try changing the Font and what was previously the Caption property. No major changes yet - so use this opportunity to dab your brow.
Now VB.NET also bundles with the regular control crew; Button (aka CommandButton), RadioButton (formerly OptionButton) and GroupBox (previously Frame). Oh, and of course the TextBox, CheckBox, PictureBox, ListBox and ComboBox - which are at least a little more self-explanatory.
Try adding each of the above controls to your form and playing with their core properties
Top Tip: You'll notice the Shape control has disappeared. Uhm, yes. However you can still add pictures to your form - and 'draw in code' using something called the System.Drawing.Graphics namespace - more on this later!
In this list, you'll also find a hot bunch of controls you wouldn't usually find on the Visual Basic 6 Toolbox. For example, you'll notice the DateTimePicker, ProgressBar and ListView controls controls you'd usually have to 'bring into' your application using the Components menu.
Now have a play with any controls you think you've seen before and know what they do
Top Tip: To see how your controls look likeat runtime, press F5 to compile and launch your application - just as in VB6
In addition to all this, you'll find controls there you've never seen before. Even I don't know what hey all do - still, let's skim over a couple of the most important.
First off, there's the MainMenu control. This is essentiallythe old Menu Builder. Let's use it.
- Add the MainMenu control to your Form
- On your Form, click in the box that now says: Type Here
- Type in: &File
- Now add a few sub-items to the new File menu
- Expand out by clicking in the 'Type Here' box to the right of 'File' - and add a number of menu
- Press F5 to run your app and test your new menu
Top Tip: Enter a single dash to add aseparator to the menu
And you can add code to these menu items in much the same way as you would in VB6. Just double-click the item and enter your jazz in the code window. But we'll be looking at all that later.
Next up, let's look at the LinkLabel. This is a control design to look like a Web page hyperlink - by default it's an underlined blue, your mouse turns into a hand when you hover over and it changes colour upon being clicked. But it isn't linked to a Web site by default - when you click it, the code under the Click event runs.Add a LinkLabel control to your FormHit F5 to run and test your new LinkLabel
Top Tip: Try checking out the LinkBehavior property for even more LinkLabel effects!
Elsewhere - and I personally find the ErrorProvider an exceptionally cool control. It will automatically highlight controls with an icon if a validation error occurs. Here's an example of it in use:
Also, the likes of ToolTips are handled differently in VB.NET - enter stage the ToolTip control. Plus, those Windows Open and Save dialogs are now accessible as 'intrinsic' controls.
Oh, and the TrayIcon control allows you to simplify adding your own icon and menu to the system tray. And the HelpProvider control allows you to easily implement helpfile access.
The list goes on! And alas in this tutorial, there's no time to cover them all in intricate detail - but if you are looking to find out more, check out the help.
Top Tip: Looking for assistance? Simply click the 'Dynamic Help' button just under the Properties window.
For now, let's move on to exploring a couple of the new and groovy form features...
Page 2 of 7