首页 > 解决方案 > 并排显示表单所有者表单

问题描述

我有一个表格。如果有人按下按钮,我想显示第二个“附加”到原始表单的表单,这意味着它的左侧位于原始表单的右侧并且它们具有相同的高度。换句话说:它们相互接触。

答案似乎是父表格旁边的开放表格

但是,图像之间存在间隙。我希望它们彼此完全相邻

在此处输入图像描述

主要形式:

private void ShowOtherForm()
{
    using (var form = new OtherForm())
    {
        var dlgResult = form.ShowDialog(this);
        ProcessDlgResult(dlgResult);
    }
}

其他形式,事件处理程序加载

private void FormLoad(object sender, EventArgs e)
{
    // show this form attached to the right side of my owner:
    this.Location = new Point(this.Owner.Right, this.Owner.Top);
    this.Height = this.Owner.Height;
}

标签: c#winforms

解决方案


尝试使用ClientSizeLocation

private void Form2_Load(object sender, EventArgs e)
{
   var owner = this.Owner;
   Location = new Point(owner.Location.X + owner.ClientSize.Width, owner.Location.Y);
   Height = owner.Height;
}

推荐阅读