| | |
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.
![]() |
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 .net2008 2005 2008 access account array basic beginner bing browser button buttons center check code crystalreport cuesent data database datagrid datagridview date datetimepicker designer dissertation dissertations dissertationtopic dropdownlist excel fade file-dialog filter forms ftp generatetags google gridview html images input insert intel internet listview mobile monitor net networking objects open output panel passingparameters pdf picturebox port position print printing problem remove save searchbox searchvb.net select serial settings shutdown soap sqlserver survey table tcp temperature text textbox timer timespan toolbox transparency trim update user vb vb.net vb.netformclosing()eventpictureboxmessagebox vb2008 vba vbnet visual visualbasic visualbasic.net visualstudio.net visualstudio2008 web winforms wpf wrapingcode year







