Hello,

I need to know how do i locate a form window on custom location at the desktop:
At application start.

EX:

Screen:

Other question: is there any idea to solve the design bugs on other Pcs?

P.S Im so newbie at VB.NET x)

Dani AI

Generated

As asked, the basic idea given by (choose a manual startup position and set the form Location) is the right starting point. The following adds a few practical improvements that make positioning work reliably across different monitors, DPI settings and when restoring a previous position — and avoids the UI freeze that can happen with long loops in Load.

A small helper to clamp a form into the working area of the screen that actually contains it (accounts for taskbar and multi‑monitor setups):

Private Sub EnsureOnScreen(frm As Form)
    Dim scr As Screen = Screen.FromControl(frm)
    Dim wa As Rectangle = scr.WorkingArea
    Dim x As Integer = frm.Left
    Dim y As Integer = frm.Top

    If x < wa.Left Then x = wa.Left
    If y < wa.Top Then y = wa.Top
    If x + frm.Width > wa.Right Then x = wa.Right - frm.Width
    If y + frm.Height > wa.Bottom Then y = wa.Bottom - frm.Height

    frm.Location = New Point(x, y)
End Sub

Restore/save a last location (store as a simple string setting) and call the clamping helper from Shown so sizes are final:

' restore (Load/Shown)
If Not String.IsNullOrEmpty(My.Settings.FormLastLoc) Then
    Dim p() = My.Settings.FormLastLoc.Split(","c)
    Me.StartPosition = FormStartPosition.Manual
    Me.Location = New Point(Integer.Parse(p(0)), Integer.Parse(p(1)))
    Me.BeginInvoke(New Action(Sub() EnsureOnScreen(Me)))
End If

' save (FormClosing)
My.Settings.FormLastLoc = String.Format("{0},{1}", Me.Left, Me.Top)
My.Settings.Save()

Design‑bug checklist (common causes): mismatched DPI or font scaling (use AutoScaleMode deliberately or supply a DPI‑aware manifest), hard‑coded pixel sizes (use anchors, docking, TableLayoutPanel/FlowLayoutPanel), different .NET/Windows themes or missing fonts, and multi‑monitor coordinates. For simple entry/exit animations prefer a Timer or native SetWindowPos rather than a tight loop in Load to keep the UI responsive.

Recommended Answers

All 3 Replies

Are you talking about choosing where the form loads from? If so, you can do this by clicking on the form and choosing the location via the Properties Menu. Just scroll down until you see the option StartPosition and then Choose Manual. Then add the following code to the Form1_Load event:

Dim x As Integer
    Dim y As Integer
    x = Screen.PrimaryScreen.WorkingArea.Width
    y = Screen.PrimaryScreen.WorkingArea.Height - Me.Height

    Do Until x = Screen.PrimaryScreen.WorkingArea.Width - Me.Width
        x = x - 1
        Me.Location = New Point(x, y)
    Loop

This will start the application from the bottom right corner.

Hope this helps :)

commented: nice :) +12

The code I have provided above will start the app on pretty much any screen resolution in the bottom right. If you want to start the app from the top left you can use this code:

Me.Location = New Point(0, 0)

What this is doing is setting the location from the points you define. The first 0 is how many pixels from the left you want the app to start from. The second 0 is how many pixels from the top you want the app to start from. So, if you have the screen resolution of 1366x768 (Standard for all 15.6" monitors) and you want the app to start in the bottom left, you would use the following code:

Me.Location = New Point(0, 768 - Me.Height)

The reason I added "- Me.Height" is because if you just have 768 it will start 768 from the top which will make the app pretty much invisible. So, adding that code does the math for you without you having to take the height of your app and subtracting it manually.

I hope I didn't lose you through this small tutorial and I hope you learned that you can pretty much set the location anywhere you would like just by a simple code.

P.S. - The most practical code to use is the first code given in my post above as it works with all screen resolutions.

EDIT:
I was messing with the codes a little bit and came up with a very effective way to choose the position with all resolutions.

Bottom Left:

Me.Location = New Point(0, Screen.PrimaryScreen.WorkingArea.Height - Me.Height)

Bottom Right:

Me.Location = New Point(Screen.PrimaryScreen.WorkingArea.Width - Me.Width, Screen.PrimaryScreen.WorkingArea.Height - Me.Height)

Top Left:

Me.Location = New Point(0, 0)

Top Right:

Me.Location = New Point(Screen.PrimaryScreen.WorkingArea.Width - Me.Width, 0)

Hope you learned something because I know I did. ;)

If it wasn't for this post, I would have never attempted to choose my location but you gave me a reason to :)

thanks bro, well work fine :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.