PictureBox没有显示在第二个相同的表单上

时间:2017-05-04 14:47:13

标签: c# winforms picturebox multiple-monitors

我有一个winforms应用程序,必须在特定条件下在两个屏幕上显示紧急消息。

这两条消息作为两个相同的表单传递,每个表单在每个屏幕上实例化。每个表单都包含一个带图像的可配置PictureBox。

当条件满足时,两个表格在两个屏幕上正确启动,但图片仅显示在两个屏幕中的一个(主屏幕)而不显示在另一个屏幕上。

表单在foreach上实例化,因此它们只在不同的屏幕上使用相同的构造函数。

表格类:

public partial class FormClearingMessage : Form
{
    public FormClearingMessage(Screen s)
    {
        InitializeComponent();
        SetParameters(s);
    }

    private void SetParameters(Screen s)
    {
        this.Top = s.Bounds.Top;
        this.Left = s.Bounds.Left;
        this.Width = s.Bounds.Width;
        this.Height = s.Bounds.Height;
        this.pictureBox1.Top = this.Top + 20;
        this.pictureBox1.Left = this.Left + 20;
        this.pictureBox1.Width = this.Width - 40;
        this.pictureBox1.Height = this.Height - 40;
        this.pictureBox1.MaximumSize = new Size(this.pictureBox1.Width, this.pictureBox1.Height);
        this.LoadImage();  
    }

    private void LoadImage()
    {
                string imagePath = Utils.ResolveSymbolicPath(c.ReadCfgEntry("clearingMessage/imagePath", null));
                if (File.Exists(imagePath))
                    this.pictureBox1.Load(imagePath);
                else
                    throw new Exception();

    }
} 

初​​始化:

        // Initialize Clearing Message forms
        Screen[] screens = Screen.AllScreens;
        _clearingMessageForms = new List<FormClearingMessage>();

        foreach (Screen s in screens)
        {
            _clearingMessageForms.Add(new FormClearingMessage(s));
        }

满足条件时的结构:

                if (singleMessage.InformationType == _infoTypeForEmergency)
                {
                    if (_clearingMessageForms != null)
                   {
                        foreach (FormClearingMessage fcm in _clearingMessageForms)
                        {
                            if (!fcm.Visible)
                                this.Invoke(new Action(() =>     {
                                    fcm.Show();
                                }));           
                        }
                    }
                }

结果:

Screens

我似乎无法发现设置有任何问题,但显然我错过了一些东西,我希望有人可以帮助我。

提前致谢!

0 个答案:

没有答案
相关问题