Search code examples
c#winformsmultiple-monitorssetbounds

Have Winform appear on all existing monitors at same time (Its an alert window)


I have a small application which functions as an alert system, I am using a form as the alert which appears on the screen, as they are more versatile and message boxes. Due to the nature of the alert, I need it to appear in the centre of all currently connected monitors.I have it appearing on hte main monitor only as of right now.

I've looked at these 2 posts on here:

Showing a Windows form on a secondary monitor?

How do I ensure a form displays on the "additional" monitor in a dual monitor scenario?

But I really can't get my head around it, I've looked into the Screens.AllScreens property, but still feel no better at understanding how to tell the form which monitor to appear on, and even further from having it appear on multiple, as I'm assuming I'd need to foreach loop through AllScreens array.

I'd also need to close all the forms from a button clock on one of them, but right now I just want to have them on all monitors.

Sorry to ask a question I feel most people consider already answered.


Solution

  • This one worked perfectly for me..

    First create an alert form with a label inside. set the label1 property -> Modifier = public

    enter image description here

    void showMsgOnAllScreens(string msg)
        {
            for (int i = 0; i < Screen.AllScreens.Length; i++)
            {
                AlertForm alert = new AlertForm();
                alert.label1.Text = msg;
                alert.StartPosition = FormStartPosition.Manual;
                alert.Location = new Point(
                    Screen.AllScreens[i].Bounds.Left + (Screen.AllScreens[i].Bounds.Width / 2 - alert.Width / 2),
                    Screen.AllScreens[i].Bounds.Height / 2 - alert.Height / 2);
                alert.Show();
            }
        }
    

    .

    .

    .

    Now simply call the method to show msgs on all screens..

    void button1_click (object sender, EventArgs e)
    {
        showMsgOnAllScreens("Warning.. Something's burning..!!");
    }