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:| 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.
Related articles
Related discussion
-
insert in master table and update in other table
by shahid123 (0 replies)
-
sending sms from pc
by sriraj20074 (0 replies)
-
add [DOT] to text line
by kayatri (0 replies)
-
Looping in text file
by kayatri (0 replies)
-
need help in designing a media player using vb.net/ocx object
by kensville (0 replies)
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...
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
It may not work with mdi children.
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,
This thread is for discussions of Windows Forms and Controls.