[英]How can i make that when i /drag/move form1 around the new form behind it will move with form1 on the same time?
我不想看到新表格。 我需要最大化他,使其大小与form1相同,但不要看到它。 因此,当我用鼠标来回移动/拖动form1时,我需要它后面的新窗体将与form1一起移动/拖动。
这是显示新表单的form1中的按钮单击事件:
private void BeginOperationBut_Click(object sender, EventArgs e)
{
if (this.imageList.Count == 0)
{
wbss = new WebBrowserScreenshots();
wbss.Show();
}
}
wbss是新形式。
我尝试在新的表单设计器中将属性Locked设置为True,但它没有做任何更改。
我想做的是两件事:
现在,当我单击按钮时,新表单将显示在form1前面。
为了确保此功能能够按预期工作,需要考虑很多因素。 这是您可以用来入门的代码片段:
public partial class FollowForm : Form {
readonly Form _master;
private FollowForm() {
InitializeComponent();
}
public FollowForm(Form master) {
if (master == null)
throw new ArgumentNullException("master");
_master = master;
_master.LocationChanged += (s, e) => Location = _master.Location;
_master.SizeChanged += (s, e) => Size = _master.Size;
ShowInTaskbar = false;
}
protected override void OnShown(EventArgs e) {
base.OnShown(e);
Location = _master.Location;
Size = _master.Size;
_master.Activate();
}
protected override void OnActivated(EventArgs e) {
_master.Activate();
}
}
我尝试使用ShowWithoutActivation
属性进行实验,但结果与我预期的不同。
主要方面是跟踪主表单的大小或位置的变化,并相应地更新跟随者表单的大小和位置。 同样,在显示时将关注者表单发送到背面并重新激活主表单。 试试看。 这来自.NET4.0项目VS2013。
public partial class MasterForm : Form {
FollowForm _follower;
public MasterForm() {
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e) {
_follower = new FollowForm(this);
_follower.Show();
}
}
为了更好地使用无激活功能,请查看:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.