| | |
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 |
"crystal .net .net2005 30minutes 2005 2008 access account arithmetic array assignment basic binary bing box button buttons center check code component connectionstring convert cpu crystalreport data database databasesearch datagrid datagridview design dissertation dissertations dissertationthesis dosconsolevb.net dropdownlist editvb.net excel file-dialog firewall folder ftp hardcopy image images insert isnumericfuntioncall login math memory mobile ms mssqlbackend mysql navigate net networking opacity output passingparameters peertopeervideostreaming picturebox1 port printpreview problemwithinstallation project record reports" reuse save savedialog serial soap storedprocedure string tcp temp text textbox timer toolbox trim update updown useraccounts usercontrol vb vb.net vb.netcode vb.netformclosing()eventpictureboxmessagebox vb.nettoolboxvisualbasic2008sidebar vb2008 vbnet view visual visualbasic visualbasic.net visualstudio web wpf







