Secondary Monitor shows part of Primary Monitor

135 views Asked by At

I have created a win app, which uses secondary monitor to show images. I have used the following code to detect and set location of secondary monitor(which is an extended monitor of primary monitor).

public void secondarydisplay()
{

    FrmSecondaryDisplay secdis = new FrmSecondaryDisplay();
    Screen[] screens = Screen.AllScreens;
    secdis.MyBase = this;
    this.MySecScreen = secdis;
    secdis.Show();
    setFormLocation(secdis, screens[1]);

}

private void setFormLocation(Form form, Screen screen)
{
    Rectangle bounds = screen.Bounds;
    form.SetBounds(bounds.X, bounds.Y, bounds.Width, bounds.Height);
    form.StartPosition = FormStartPosition.Manual;

}

Problem is i am getting this thin 6mm white line on the left most corner of the secondary display. which is nothing but the extension of primary display. how do i make it disapper? on moving the cursor to secondary monitor and click on the screen of secondary monitor this white line disappears. and on moving back the cursor to primary monitor and click on it makes the white line appear on secondary monitor. kindly help me how can i resolve this issue. it looks ugly in secondary mopnitor.

1

There are 1 answers

1
Eric On BEST ANSWER

Always prepared the window properties before Show()

public void Secondarydisplay()
{

    if (Screen.AllScreens.Count() == 1)
    {
        return; // No second display
    }

    var secdis = new FrmSecondaryDisplay();

    // Actually you shall use secdis.Show(this) to build the relation of the forms. 
    // When "this" closes, the second display form closes.
    secdis.MyBase = this; 
    this.MySecScreen = secdis;


    // Setup Windows Position before Show()
    secdis.StartPosition = FormStartPosition.Manual;
    secdis.Location = Screen.AllScreens[1].WorkingArea.Location;
    secdis.TopMost = true;
    secdis.FormBorderStyle = FormBorderStyle.None;
    secdis.WindowState = FormWindowState.Maximized;

    secdis.Show(this); // See comment above
}