943,365 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 43036
  • VB.NET RSS
You are currently viewing page 1 of this multi-page discussion thread
Jun 25th, 2003
1

Centering a form in VB.NET

Expand Post »
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.
Similar Threads
Team Colleague
Reputation Points: 211
Solved Threads: 27
Master Poster
Paladine is offline Offline
793 posts
since Feb 2003
Jul 2nd, 2003
1

Re: Centering a form in VB.NET

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
------------------------------------------------------------------------------
Reputation Points: 13
Solved Threads: 0
Light Poster
Mr Gates is offline Offline
36 posts
since May 2003
Jul 2nd, 2003
1

Re: Centering a form in VB.NET

I'm 99% sure that this requires no code - its in the properties window for the form :-).
Moderator
Reputation Points: 322
Solved Threads: 28
The C# Man, Myth, Legend
Tekmaven is offline Offline
914 posts
since Feb 2002
Jul 2nd, 2003
0

Re: Centering a form in VB.NET

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.
Reputation Points: 13
Solved Threads: 0
Light Poster
Mr Gates is offline Offline
36 posts
since May 2003
Jul 2nd, 2003
0

Re: Centering a form in VB.NET

Is there a form layout window in .NET? lol

This is what I am talking about:
[img]http://tekmaven.dizla.com/centerscreen.jpg[/img]
Moderator
Reputation Points: 322
Solved Threads: 28
The C# Man, Myth, Legend
Tekmaven is offline Offline
914 posts
since Feb 2002
Jul 2nd, 2003
0

Re: Centering a form in VB.NET

:o I really need to think about getting .NET

Yea, I suppose that would work. hehe.
Reputation Points: 13
Solved Threads: 0
Light Poster
Mr Gates is offline Offline
36 posts
since May 2003
Jul 2nd, 2003
1

Re: Centering a form in VB.NET

they have that same property for vb6 also, for those of us using vb6 still
Team Colleague
Reputation Points: 36
Solved Threads: 2
PFO Founder
big_k105 is offline Offline
308 posts
since May 2003
Jul 2nd, 2003
0

Re: Centering a form in VB.NET

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 :-).
Moderator
Reputation Points: 322
Solved Threads: 28
The C# Man, Myth, Legend
Tekmaven is offline Offline
914 posts
since Feb 2002
Jul 2nd, 2003
0

Re: Centering a form in VB.NET

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.
Administrator
Staff Writer
Reputation Points: 1422
Solved Threads: 162
The Queen of DaniWeb
cscgal is offline Offline
13,645 posts
since Feb 2002
Jul 6th, 2003
0

Re: Centering a form in VB.NET

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.
Team Colleague
Reputation Points: 211
Solved Threads: 27
Master Poster
Paladine is offline Offline
793 posts
since Feb 2003
Message:
Previous Thread in VB.NET Forum Timeline: code conversion VB6 to VB.Net
Next Thread in VB.NET Forum Timeline: Problem with Deleting Panels





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC