子形式遵循主要形式 [英] Child form follow main form
本文介绍了子形式遵循主要形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使子窗体遵循主窗体。
例如:打开一个winform [.net2],winform打开窗体,如果mainform为移动。
解决方案
使用MainForm中的 LocationChanged
事件始终设置ChildForm的位置。 / p>
工作示例:
Form childForm = new Form();
受保护的覆盖无效OnLoad(EventArgs e){
base.OnLoad(e);
childForm.StartPosition = FormStartPosition.Manual;
childForm.Width = this.Width;
childForm.Height = 96;
childForm.Location = new Point(this.Left,this.Bottom);
childForm.Show();
}
受保护的覆盖无效OnLocationChanged(EventArgs e){
base.OnLocationChanged(e);
if(childForm!= null){
childForm.Location = new Point(this.Left,this.Bottom);
}
}
How to make the child form follow main form.
for example: open a winform [.net2], winform opens form, form follows the mainform if mainform is moving.
解决方案
Use the LocationChanged
event from the MainForm to always set the location of the ChildForm.
Working example:
Form childForm = new Form();
protected override void OnLoad(EventArgs e) {
base.OnLoad(e);
childForm.StartPosition = FormStartPosition.Manual;
childForm.Width = this.Width;
childForm.Height = 96;
childForm.Location = new Point(this.Left, this.Bottom);
childForm.Show();
}
protected override void OnLocationChanged(EventArgs e) {
base.OnLocationChanged(e);
if (childForm != null) {
childForm.Location = new Point(this.Left, this.Bottom);
}
}
这篇关于子形式遵循主要形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文