| | |
Centering a form in VB.NET
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
Just got to playing around, and felt that the VB forum on here could use some posts.
What I was playing around with forms in VB.NET and wanted to hard code centering a form. Here is what I found...and if anyone has an easier or slicker way...let me know.
-in the windows form generated code portion of a form in VB.NET ad the following line:
Me.StartPosition = FormStartPosition.CenterScreen
-Note: to work this must be placed in the Form1 (or whatever form name) initialization code.
What I was playing around with forms in VB.NET and wanted to hard code centering a form. Here is what I found...and if anyone has an easier or slicker way...let me know.
-in the windows form generated code portion of a form in VB.NET ad the following line:
Me.StartPosition = FormStartPosition.CenterScreen
-Note: to work this must be placed in the Form1 (or whatever form name) initialization code.
•
•
Join Date: May 2003
Posts: 36
Reputation:
Solved Threads: 0
I've started using this code, since it works no matter what the screen resolution is on the user's monitor. It only does it when you start up the program, but I assume that's what you want. (I always use the prefix frm for the names of forms. In this case the form name is SampApplication
Code:
------------------------------------------------------------------------------
frmSampApplication.Left = (Screen.Width - frmSampApplication.Width) / 2
frmSampApplication.Top = (Screen.Width - frmSampApplication.Height) / 2
------------------------------------------------------------------------------
Code:
------------------------------------------------------------------------------
frmSampApplication.Left = (Screen.Width - frmSampApplication.Width) / 2
frmSampApplication.Top = (Screen.Width - frmSampApplication.Height) / 2
------------------------------------------------------------------------------
I'm 99% sure that this requires no code - its in the properties window for the form :-).
-Ryan Hoffman
.NET Specialist / Webmaster, Extended64.com.
Please do not email or PM me with support questions. Please direct them to the forums instead.
.NET Specialist / Webmaster, Extended64.com.
Please do not email or PM me with support questions. Please direct them to the forums instead.
•
•
Join Date: May 2003
Posts: 36
Reputation:
Solved Threads: 0
I'm not exactly sure you can do it in the properties window, or at least get it to the exact location. It would require a lot more work than needed. If you are talking about the form layout window, you can try to center it in there, but again, it would be very hard to get it to the exact spot, and it wouldn't work on all resolutions.
Is there a form layout window in .NET? lol
This is what I am talking about:
http://tekmaven.dizla.com/centerscreen.jpg
This is what I am talking about:
http://tekmaven.dizla.com/centerscreen.jpg
-Ryan Hoffman
.NET Specialist / Webmaster, Extended64.com.
Please do not email or PM me with support questions. Please direct them to the forums instead.
.NET Specialist / Webmaster, Extended64.com.
Please do not email or PM me with support questions. Please direct them to the forums instead.
I love .NET. I actually live for .NET.
If your a VB6 programmer... it has somewhat of a learning curve to go .NET... but it will be extremely rewarding.
Not only is .NET 100x faster, but its more powerfull too :-).
If your a VB6 programmer... it has somewhat of a learning curve to go .NET... but it will be extremely rewarding.
Not only is .NET 100x faster, but its more powerfull too :-).
-Ryan Hoffman
.NET Specialist / Webmaster, Extended64.com.
Please do not email or PM me with support questions. Please direct them to the forums instead.
.NET Specialist / Webmaster, Extended64.com.
Please do not email or PM me with support questions. Please direct them to the forums instead.
Ryan, do you think you'd be able to resize the screenshot you have posted. It's sorta annoying that I keep having to horizontally scroll everytime I visit this page.
Dani the Computer Science Gal 
Follow my Twitter feed! twitter.com/DaniWeb
And if you're interested in Internet marketing there is twitter.com/DaniWebAds

Follow my Twitter feed! twitter.com/DaniWeb
And if you're interested in Internet marketing there is twitter.com/DaniWebAds
![]() |
Other Threads in the VB.NET Forum
- Previous Thread: Application Identification help needed
- Next Thread: ADO.NET question modification.
| Thread Tools | Search this Thread |
.net 30minutes 2005 2008 access account arithmetic array basic bing button buttons c# center check code combobox component connectionstring convert crystalreport data database databasesearch datagrid datagridview date design dissertation dissertations dropdownlist excel fade file-dialog folder ftp generatetags google gridview hardcopy images inline input insert intel internet listview mobile monitor ms net networking objects output passingparameters peertopeervideostreaming picturebox picturebox1 plugin port print problem problemwithinstallation project remove save searchbox searchvb.net select serial server shutdown soap survey table tcp temperature text textbox timer toolbox trim update updown user vb vb.net vb.netcode vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet view visual visualbasic visualbasic.net visualstudio visualstudio2008 web winforms wpf






