Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
biohazardxxx opened this issue Sep 11, 2024 · 0 comments
Open

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

biohazardxxx opened this issue Sep 11, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@biohazardxxx
Copy link

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

@biohazardxxx biohazardxxx added the bug Something isn't working label Sep 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant