Centering a form in VB.NET

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Feb 2003
Posts: 793
Reputation: Paladine has a spectacular aura about Paladine has a spectacular aura about Paladine has a spectacular aura about 
Solved Threads: 26
Team Colleague
Paladine's Avatar
Paladine Paladine is offline Offline
Master Poster

Centering a form in VB.NET

 
1
  #1
Jun 25th, 2003
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.
Assistant Manager, Pharmacy Informatics
Wordpress Learning Blog
Updated : ASP.Net Login Code
Reply With Quote Quick reply to this message  
Join Date: May 2003
Posts: 36
Reputation: Mr Gates is an unknown quantity at this point 
Solved Threads: 0
Mr Gates Mr Gates is offline Offline
Light Poster

Re: Centering a form in VB.NET

 
1
  #2
Jul 2nd, 2003
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
------------------------------------------------------------------------------
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 898
Reputation: Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light 
Solved Threads: 28
Moderator
Tekmaven's Avatar
Tekmaven Tekmaven is offline Offline
The C# Man, Myth, Legend

Re: Centering a form in VB.NET

 
1
  #3
Jul 2nd, 2003
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.
Reply With Quote Quick reply to this message  
Join Date: May 2003
Posts: 36
Reputation: Mr Gates is an unknown quantity at this point 
Solved Threads: 0
Mr Gates Mr Gates is offline Offline
Light Poster

Re: Centering a form in VB.NET

 
0
  #4
Jul 2nd, 2003
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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 898
Reputation: Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light 
Solved Threads: 28
Moderator
Tekmaven's Avatar
Tekmaven Tekmaven is offline Offline
The C# Man, Myth, Legend

Re: Centering a form in VB.NET

 
0
  #5
Jul 2nd, 2003
Is there a form layout window in .NET? lol

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.
Reply With Quote Quick reply to this message  
Join Date: May 2003
Posts: 36
Reputation: Mr Gates is an unknown quantity at this point 
Solved Threads: 0
Mr Gates Mr Gates is offline Offline
Light Poster

Re: Centering a form in VB.NET

 
0
  #6
Jul 2nd, 2003
:o I really need to think about getting .NET

Yea, I suppose that would work. hehe.
Reply With Quote Quick reply to this message  
Join Date: May 2003
Posts: 307
Reputation: big_k105 is an unknown quantity at this point 
Solved Threads: 2
Team Colleague
big_k105's Avatar
big_k105 big_k105 is offline Offline
PFO Founder

Re: Centering a form in VB.NET

 
1
  #7
Jul 2nd, 2003
they have that same property for vb6 also, for those of us using vb6 still
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 898
Reputation: Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light 
Solved Threads: 28
Moderator
Tekmaven's Avatar
Tekmaven Tekmaven is offline Offline
The C# Man, Myth, Legend

Re: Centering a form in VB.NET

 
0
  #8
Jul 2nd, 2003
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 :-).
-Ryan Hoffman

.NET Specialist / Webmaster, Extended64.com.
Please do not email or PM me with support questions. Please direct them to the forums instead.
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 12,043
Reputation: cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light 
Solved Threads: 129
Administrator
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

Re: Centering a form in VB.NET

 
0
  #9
Jul 2nd, 2003
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2003
Posts: 793
Reputation: Paladine has a spectacular aura about Paladine has a spectacular aura about Paladine has a spectacular aura about 
Solved Threads: 26
Team Colleague
Paladine's Avatar
Paladine Paladine is offline Offline
Master Poster

Re: Centering a form in VB.NET

 
0
  #10
Jul 6th, 2003
Well bite my tongue. I guess I need to start looking more at the properties window. Hehe...

Guess I was punch drunk or something.

Thanks for the tip on the tip.

Except the screen width code noted above is VB6, and not .NET.
Assistant Manager, Pharmacy Informatics
Wordpress Learning Blog
Updated : ASP.Net Login Code
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the VB.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC