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
-
Error in VB code
by glib162002 (0 replies)
-
i have struck with my project in vb.net
by gangireddysaritha (1 replies)
-
Very slow inserts using SqlCommand.ExecuteNonQuery()
by porchelvi (1 replies)
-
Datagridview Setting datasource property of datagridviewcomboboxcell at run time
by sairfan1 (2 replies)
-
vb.net mp3 +g player
by novavb6 (1 replies)
Related jobs
-
Microsoft .Net Architect
in AMSTERDAM (€50K-€90K per annum)
Events coming up
-
Dec
6
Developing AJAX Web Applications with Castle Monorail
London, United Kingdom
Monorail is the model-view-controller engine of the Castle Project, bringing many of the best ideas of Ruby on Rails to the .NET world. In this talk, David De Florinier and Gojko Adzic show how Monorail makes it easy to develop .NET based AJAX applications, and how to use the Castle Project to build Web 2.0 applications effectively. Come to this session if you are a .NET web developer. Everyone is welcome!
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.