Skip to content

MetroForm not movable on left screen (of 3) #177

@biohazardxxx

Description

@biohazardxxx

Bug explanation

When setting position of the form to be on left of 3 screens (Screen.AllScreens[0]), the form window can not be moved. The cursor changes to resize arrow when hovering the form (not only header. Also Only resizing the window is possible.
Strange is that it works fine on center and right screen. It works fine with MaterialForm.
Partial class as example for a blank designer created form.

public partial class TEST : MetroForm
{
    public TEST()
    {
        InitializeComponent();
        this.ShowHeader = true;
        this.ShowLeftRect = false;
        MoveFormToCenterOfSecondaryScreen(this);
    }

    public void MoveFormToCenterOfSecondaryScreen(Form form)
    {
        // Check if there is more than one screen (secondary screen exists)
        if (Screen.AllScreens.Length > 1)
        {
            // Get the secondary screen (usually the second in the list)
            Screen secondaryScreen = Screen.AllScreens[0];

            // Get the working area of the secondary screen (excludes taskbar and other docked elements)
            Rectangle workingArea = secondaryScreen.WorkingArea;

            // Calculate the centered position
            int centerX = workingArea.Left + (workingArea.Width - form.Width) / 2;
            int centerY = workingArea.Top + (workingArea.Height - form.Height) / 2;

            // Move the form to the center of the secondary screen
            form.StartPosition = FormStartPosition.Manual;
            form.Location = new Point(centerX, centerY);
        }
        else
        {
            // If there's no secondary screen, fallback to center on the primary screen
            form.StartPosition = FormStartPosition.CenterScreen;
        }
    }

}

image

Version

3.8.0.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions