0

我有一个类可以处理一种用户控件弹出窗口,它通过从 System.Windows.Forms.ToolStripDropDown 继承来工作。这适用于我目前拥有的弹出类型,我将在下面详细说明;

首先,是我用来以弹出式样式保存用户控件的类;

 public class PopupWindow : System.Windows.Forms.ToolStripDropDown
{
    private System.Windows.Forms.Control _content;
    private System.Windows.Forms.ToolStripControlHost _host;

    public PopupWindow(System.Windows.Forms.Control content)
    {
        //Basic setup...
        this.AutoSize = false;
        this.DoubleBuffered = true;
        this.ResizeRedraw = true;
        this.BackColor = content.BackColor;

        this._content = content;
        this._host = new System.Windows.Forms.ToolStripControlHost(content);

        //Positioning and Sizing
        this.MinimumSize = content.MinimumSize;
        this.MaximumSize = content.Size;
        this.Size = content.Size;
        content.Location = Point.Empty;

        //Add the host to the list
        this.Items.Add(this._host);
    }
}

正如我们在这里看到的,我只是将一个控件传递给它,并让它完成工作。当在“onclick”弹出窗口上使用它时,就像这样,它工作正常;

 public void Popup(object sender, MouseEventArgs e, other params)
    {

        DevicePopup popupDevice = new DevicePopup();

          //do stuff to the control here before displaying

        PopupWindow popup = new PopupWindow(popupDevice);
        popup.Show(Cursor.Position);

    }

并这样称呼它;

  this.Controls[btnAdd.Name].MouseClick += (sender, e) =>
            {
                int index = temp;
                generatePopup.Popup(sender, e, mDevices[index], this);
            };

这样做可以按预期在我的鼠标单击时成功创建弹出用户控件。

但是,我现在正在尝试使用第二种类型的弹出窗口,它会在发生某些事情时产生。下面是我的新弹出类,并调用它;

public void AlarmNotificationPopup(IDeviceInterface device)
     {


         try
         {
             AlarmNotification ANotification = new AlarmNotification();

       //do stuff to the control again before displaying


             PopupWindow popup = new PopupWindow(ANotification);
             popup.Show(100, 100);


         }
         catch (Exception e)
         {
             MessageBox.Show(e.Message);
         }


     }


    AlarmNotificationPopup(device);

但是,这个弹出窗口没有正确渲染/创建,看起来像这样;

渲染问题

我不完全确定如何解决这个问题。有人有想法么?

4

1 回答 1

0

有几件事可以尝试:

我认为您不需要“基本设置”,因此请注释掉。另外,尝试设置您的边距和填充:

public PopupWindow(Control content) {
  // Basic setup...
  // this.AutoSize = false;
  // this.DoubleBuffered = true;
  // this.ResizeRedraw = true;
  // this.BackColor = content.BackColor;

  this._content = content;
  this._host = new ToolStripControlHost(content);
  this._host.Margin = new Padding(0);
  this._host.Padding = new Padding(0);
  this.Padding = new Padding(0);
  this.Margin = new Padding(0);

  //Positioning and Sizing
  this.MinimumSize = content.MinimumSize;
  this.MaximumSize = content.Size;
  this.Size = content.Size;
  content.Location = Point.Empty;

  //Add the host to the list
  this.Items.Add(this._host);
}

确保你AlarmNotification有它的MinimumSize属性集。

如果这无助于解决问题,那么您可能需要记录AlarmNotification班级正在做什么。

于 2012-06-15T13:33:09.620 回答