|
-
Jan 6th, 2015, 11:10 AM
#1
Thread Starter
Lively Member
[RESOLVED] Form Starting Location
In VB 2008, there is a option in the Form- properties which lets you select where the form starts up at. Some of the options include Windows Default, Center Screen & manual. Well I would like some of my Apps to start up at the top of the screen or at the bottom. Basically, I need a customizable way of debating where the form starts at.
Uses for this- I can have a small application start at the top of the screen without it being in the way of what the user is currently doing.
A code would be nice to have or perhaps a simple tutorial to use all types of form locations.
-
Jan 6th, 2015, 11:16 AM
#2
Re: Form Starting Location
The location property is what you're looking for, however it's best to do it in the form's load or shown event programmatically to allow for the form to completely load it's other properties first. For example, if you wanted the form to be in the bottom left hand corner of the screen you'd use this:
Code:
Me.Location = New Point(0, My.Computer.Screen.Bounds.Bottom - Me.Height)
If you wanted it to be at the upper-right hand corner then you'd use this:
Code:
Me.Location = New Point(My.Computer.Screen.Bounds.Right - Me.Width, 0)
-
Jan 6th, 2015, 11:17 AM
#3
Re: Form Starting Location
<edit> Too slow...<edit>
I would just set the desired location in the Shown event handler.
Code:
Private Sub SimControl_Shown(sender As Object, e As System.EventArgs) Handles Me.Shown
Me.Location = New Point(400, 0) 'Put window at the top, 400 pixels from the right of the main screen
End Sub
-
Jan 6th, 2015, 11:19 AM
#4
Thread Starter
Lively Member
Re: Form Starting Location
That helps a lot. But how would I do it through the properties of the form?
-
Jan 6th, 2015, 11:24 AM
#5
Lively Member
Re: Form Starting Location
If you have a class that determines what type of user they are, eg Admin, User etc then you can create a Select Case statement on start up that will position the form in a certain position based off their status:
Code:
Public Sub New()
InitializeComponent()
Select Case TypeOfUser
Case "Admin"
Me.Location = New Point(100, 50)
Case "User"
Me.Location = New Point(250, 250)
End Select
End Sub
I just wrote this in Visual Studio, I didn't test it out so if you have any problems let me know!
EDIT: Or like passel said, you could place it in the Shown event handler.
-
Jan 6th, 2015, 11:28 AM
#6
Thread Starter
Lively Member
Re: Form Starting Location
That would be useful. But what I'm looking for is how to use the Form-Properties-Startup Location on the Designer. I need to know how I can manually set it or dock it to a specific place
-
Jan 6th, 2015, 11:32 AM
#7
Lively Member
Re: Form Starting Location
Correct me if I'm wrong, but I do not think it is possible on the properties tab. Like in previous examples on this thread, you can do it manually by code and won't take too long to implement.
-
Jan 6th, 2015, 11:34 AM
#8
Re: Form Starting Location
 Originally Posted by kshadow22
That would be useful. But what I'm looking for is how to use the Form-Properties-Startup Location on the Designer. I need to know how I can manually set it or dock it to a specific place
I addressed it in my first post, you'd set the form's location in the properties window. However, it is better to set it via code because whenever you set the form's location via the designer it is inconsistent.
-
Jan 6th, 2015, 11:34 AM
#9
Re: Form Starting Location
 Originally Posted by kshadow22
That would be useful. But what I'm looking for is how to use the Form-Properties-Startup Location on the Designer. I need to know how I can manually set it or dock it to a specific place
I addressed it in my first post, you'd set the form's location in the properties window. However, it is better to set it via code because whenever you set the form's location via the designer it is inconsistent.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|