In this tutorial on Visual Basic Controls and Properties you will gain an understanding on how easy it is to quickly create rich interfaces for your Visual Basic applications. You merely drag controls onto a form, style those controls to how you like them and manipulate those controls using the properties Visual Basic exposes on them.
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 of any sort in other languages meant typing an awful lot. Dull, laborious, error strewn typing at that. Typing what control to put where, 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 your screen or a window on your screen. A control in Visual Basic is something that can capture a user input or display a piece of information. A button is a classic example, you can put a button anywhere you want on the form, drag it larger or smaller, change its colour, set some text, all by accessing it’s property list and manipulating those properties. The properties define how the button looks, where is is positioned, the text on the button and what events to fire when the button is e.g. clicked. The properties define the button.
The controls are all accessed from the Visual Basic Toolbox which we briefly looked at when creating the Hello World program.
The Properties window manipulate the properties
Go on, try it now, create a new Visual Basic project, 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.
Something like this.
How easy was 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 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, the textbox – for entering or displaying text, the label – for displaying text, the listbox – for showing lists of items and the combobox – for displaying a dropdown list of items.
The following tutorial uses controls and properties to tell the end user the Meaning of Life. I kid you not. It’s incredible.