Search code examples
vb.netwinformsposition

VB.NET Form Position to Bottom


It may be a stupid question...but how can I make a Windows Form to load from the Bottom of the screen in VB.NET? I have tried using Form Location but it only have Center Screen ETC. :( Also tried this code...but not exactly what I would like..

Dim x As Integer
        Dim y As Integer
        x = Screen.PrimaryScreen.WorkingArea.Width - 400
        y = Screen.PrimaryScreen.WorkingArea.Height - 270
        Me.Location = New Point(x, y)

I'm Making a App that runs In Maximized Mode so it fills the whole screen. I want the app to have its own keyboard (a form with buttons that acts like keys!) that have to appear at the bottom (like the keyboard appears on the bottom of the screen at any Android / IOS Phone


Solution

  • If you want your form centered at the bottom of the primary screen, you can use this code in the form's Load event handler.

    Dim x As Integer = (Screen.PrimaryScreen.WorkingArea.Width - Me.Width) \ 2
    Dim y As Integer = Screen.PrimaryScreen.WorkingArea.Height - Me.Height
    Me.Location = New Point(x, y)
    

    In your comments, you ask about positioning the form at the bottom of the screen but filling the width of the screen. You can do that like this.

    Dim y As Integer = Screen.PrimaryScreen.WorkingArea.Height - Me.Height
    Me.Location = New Point(0, y)
    Me.Width = Screen.PrimaryScreen.WorkingArea.Width