【发布时间】:2012-06-15 09:07:42
【问题描述】:
我有一个类可以处理一种用户控件弹出窗口,它通过从 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);
但是,这个弹出窗口没有正确渲染/创建,看起来像这样;
我不完全确定如何解决这个问题。有人有什么想法吗?
【问题讨论】:
-
查看控件的填充和边距。他们是对的吗?
-
据我所知看起来一样。
标签: c# winforms controls drawing