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

亡梦爱人 提交于 2019-12-13 02:27:10

问题


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.


回答1:


This one worked perfectly for me..

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

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..!!");
}


来源:https://stackoverflow.com/questions/25627757/have-winform-appear-on-all-existing-monitors-at-same-time-its-an-alert-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!