Windows Forms and Controls

Introduction

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:

PropertySettings:FormLabelTextBox
Name frmMainlblEnterTexttxtEnteredText
Anchor  top, left (default)Top, Right
Font Verdana  
GridSize 4, 4  
Location  20, 28132, 24
MinimumSize 200, 100  
Opacity 80%  
Size 300, 180100, 16100, 21
TabIndex  01
Text  Enter Text[blank]
TextAlign  MiddleLeftLeft


PropertySettings:Button1Button2
Name cbAcceptcbCancel
Anchor Bottom, RightBottom, Right
Location 112, 108204, 108
Size 75, 2375, 23
TabIndex 23
Text AcceptCancel
TextAlign MiddleCenterMiddleCenter

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.

You might also like...

Comments

About the author

Brian O'Connell Ireland

Microsoft Certified Applications Developer with 10 years experience developing web based applications using asp, asp.net for a Local Authority in Dublin. Clings to a firm belief that a web appli...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time.” - Tom Cargill