Ameena
Ameena

Reputation: 187

Secondary Monitor shows part of Primary Monitor

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.

Upvotes: 1

Views: 134

Answers (1)

Eric
Eric

Reputation: 5733

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
}

Upvotes: 2

Related Questions