Results 1 to 9 of 9

Thread: [RESOLVED] Form Starting Location

  1. #1

    Thread Starter
    Lively Member kshadow22's Avatar
    Join Date
    Dec 2014
    Location
    Kentucky
    Posts
    95

    Resolved [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.

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,370

    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)
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  3. #3
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,598

    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

  4. #4

    Thread Starter
    Lively Member kshadow22's Avatar
    Join Date
    Dec 2014
    Location
    Kentucky
    Posts
    95

    Re: Form Starting Location

    That helps a lot. But how would I do it through the properties of the form?

  5. #5
    Lively Member
    Join Date
    Aug 2014
    Posts
    77

    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.

  6. #6

    Thread Starter
    Lively Member kshadow22's Avatar
    Join Date
    Dec 2014
    Location
    Kentucky
    Posts
    95

    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

  7. #7
    Lively Member
    Join Date
    Aug 2014
    Posts
    77

    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.

  8. #8
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,370

    Re: Form Starting Location

    Quote Originally Posted by kshadow22 View Post
    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.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  9. #9
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,370

    Re: Form Starting Location

    Quote Originally Posted by kshadow22 View Post
    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.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

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
  •  



Click Here to Expand Forum to Full Width