Library tutorials & articles

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.

Comments

  1. 01 Aug 2008 at 19:22

     Only 5 years after the last post eh :) Anyway because things may have changed I recommend you look at the microsoft docs on this - http://msdn.microsoft.com/en-us/library/ms229597(VS.80).aspx

  2. 22 Oct 2003 at 16:26

    It may not work with mdi children.

  3. 11 Jul 2003 at 03:26

    I use VB.Net (framework 1.0.3705) on Windows 2000, and I noticed the 'MinimumSize' property doesn't seem to have any effect on my forms (MDIChildren). Does that property really prevent users from resizing a form to a smaller size than the MinimumSize? Any other experiences?


    Thank you,

  4. 01 Jan 1999 at 00:00

    This thread is for discussions of Windows Forms and Controls.

Leave a comment

Sign in or Join us (it's free).

Brian O'Connell 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 applicat...
AddThis

Related discussion

Related podcasts

  • xpert to Expert: Inside Concurrent Basic (CB)

    "Concurrent Basic extends Visual Basic with stylish asynchronous concurrency constructs derived from the join calculus. Our design advances earlier MSRC work on Polyphonic C#, Comega and the Joins Library. Unlike its C# based predecessors, CB adopts a simple event-like syntax familiar to VB progr...

We'd love to hear what you think! Submit ideas or give us feedback