Windows Forms and controls at first won’t appear that different to regular VB programmers but there are some important differences and changes that are worth noting right from the start. I’m going to attempt to show you how to create forms and controls in the VS.Net designer, set their properties, create a second form using inheritance and then dig into doing all of the above but with just code. I’m going to assume you know a bit about the VS.Net environment so I don’t have to explain every little detail.
Your First Form with controls
Lets cover some of the basics first. Start a Visual Basic.Net Windows Application project and call it FormsAndControls (doesn’t really matter what you call it). Once your project has loaded you should immediately see a form in designer mode. Add a label, textbox and 2 buttons to the form.
Now lets set a few properties. First the form:Property | Settings: | Form | Label | TextBox |
Name | frmMain | lblEnterText | txtEnteredText | |
Anchor | top, left (default) | Top, Right | ||
Font | Verdana | |||
GridSize | 4, 4 | |||
Location | 20, 28 | 132, 24 | ||
MinimumSize | 200, 100 | |||
Opacity | 80% | |||
Size | 300, 180 | 100, 16 | 100, 21 | |
TabIndex | 0 | 1 | ||
Text | Enter Text | [blank] | ||
TextAlign | MiddleLeft | Left |
Property | Settings: | Button1 | Button2 |
Name | cbAccept | cbCancel | |
Anchor | Bottom, Right | Bottom, Right | |
Location | 112, 108 | 204, 108 | |
Size | 75, 23 | 75, 23 | |
TabIndex | 2 | 3 | |
Text | Accept | Cancel | |
TextAlign | MiddleCenter | MiddleCenter |
O.K. first off lets deal with a little quirk of VS.Net. Start the project (F5 or Video-like play button) and you’ll get an error. Why? Because we renamed our form and VS.Net very unintelligently forgot to change the startup object to the newly named form. To fix this right-click on the project in the solution explorer box and select properties. From here we can set our startup object. Click the drop-down list and select frmMain. Now our project should start without any problems.
Comments