[英]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.