Visual Basic Controls and Properties provide a simple means to quickly create rich interfaces for your Visual Basic applications. You create an interface using drag and drop and within minutes you’ll be dragging Controls onto a Form and styling those Controls using their Properties. This tutorial will show you how.
What Visual Basic provides out of the box is known as a WYSISWG (What You See Is What You Get) Form editor. Visual Basic 3.0 was my first introduction to WYSIWYG and I was literally blown away. Creating a Form in other languages typically meant an awful lot of typing – dull and repetitive typing at that. You were forced to type the coordinates of where to place a Control on your screen, how to display it and how to action it. I knew there had to be a better way, and Visual Basic was it as far as I was concerned.
I’ve referred to a Form a couple of times now without any explanation, sorry about that, I got ahead of myself there. A Form in Visual Basic is essentially a window on your screen. A Control is something to capture user input or display a piece of information on this Form. A button is a classic example of a Visual Basic Control. You can place a button anywhere you want on a form using nothing but your mouse. You can drag it to be larger or smaller. Changing its colour or putting some text on it can be done by accessing the Control’s Property list and manipulating those Properties. The Properties define how the button looks, where it’s positioned, the text on the button and what events to fire when the button is e.g. clicked. The properties essentially define the behaviours and appearance of the button (or any Control for that matter).
All the Visual Basic Controls are accessed from the Visual Basic Toolbox which we briefly looked at when creating the Hello World program. The following picture shows the Toolbox, which contains all the Controls you can put on your Forms.
When you have the Control on a Form, you use the following properties window to manipulate the Control’s Properties. The text, the colour, the appearance are all controlled in this Window.
Go on, try it now, create a new Visual Basic project and drag a button into the middle of a form. Resize that button. Change the Text property to Click Me. Change the Name to buttonClickMe. Change the back colour to white.
Go on, try it! It should look something like this.
How easy was that! If you actually did try, you’d have noticed that it was so intuitive I didn’t have to tell you how to add the button, how to resize, how to position, how to change colour. It was all so amazingly obvious. No instructions were needed. What you achieved there in only a few minutes would have taken much (much!) longer in one of the older text driven languages. Amazingly, some of the newer, more modern languages have dropped this WYSIWYG concept altogether. It amazes me to walk round my office and see developers working with text editor, typing where to put controls on a form. There is a better way than that!
As you’d expect, all the various variants of Visual Basic have their own sets of controls. However common controls include the:
- Button – for clicking
- Textbox – for entering or displaying text
- Label – for displaying read only text
- Listbox – for showing lists of items
- Combobox – for displaying a dropdown list of items.
The following video tutorial demonstrates visually how you can create rich user interfaces using these Controls and Properties in Visual Basic.