调整父窗体控件大小时调整子窗体控件大小
我正在尝试找出一种简单的方法来根据父窗体的大小重新调整子窗体的大小。即子窗体从父窗体(FixedToolWindow)中弹出。
目前,为了做到这一点,我通过在我的表单子类中添加 OnParentResize 事件来实现这一目标。即
void OnParentResized(object sender, EventArgs e)
{
//Resize of the form shall be made only when the form is not minimized
if (parent.WindowState != FormWindowState.Minimized)
{
int iWidth = parent.Size.Width;
int iHeight = parent.Size.Height;
double dXFactor = (double)iWidth / (double)this.Width;
double dYFactor = (double)iHeight / (double)this.Height;
this.Scale(new SizeF((float)dXFactor, (float)dYFactor));
}
}
行 this.Scale(new SizeF((float)dXFactor, (float)dYFactor)); 缩放我的子窗体中的所有控件。
当我使用它时,我认为每当父窗体调整大小时,我的子窗体也会这样做。显然我在这里面临一个问题,子窗体内的所有控件都锚定在左上角。
最初,我的子窗体中的所有控件都具有正常大小。
调整父窗体的大小以使其变小,子窗体也会缩小到相同的系数。
现在我将父表单的大小增加回其原始大小。子窗体上的控件大小现在以更高的比例增加。而且控件也显得不合适。
任何人都可以针对这种情况提出更好的方法吗?
干杯
I'm trying to figure out a easy way to re-size my child form based on the size of the parent form. i.e The child form pops out of the parent form (FixedToolWindow).
To do this presently i'm achieving this by having a OnParentResize event in my form child class. i.e
void OnParentResized(object sender, EventArgs e)
{
//Resize of the form shall be made only when the form is not minimized
if (parent.WindowState != FormWindowState.Minimized)
{
int iWidth = parent.Size.Width;
int iHeight = parent.Size.Height;
double dXFactor = (double)iWidth / (double)this.Width;
double dYFactor = (double)iHeight / (double)this.Height;
this.Scale(new SizeF((float)dXFactor, (float)dYFactor));
}
}
The line this.Scale(new SizeF((float)dXFactor, (float)dYFactor));
scales all the controls in my child form.
When i use this i presume that whenever the parent form resizes, my child form does as well. Apparently i face a problem here, all the controls inside the child form are anchored to top-left.
Initially all the controls in my child form are of normal size.
Parent form is resized to make it small, the child form shrinks to the same factor as well.
Now i increase the size of my parent form back to its original size. The size of the controls on the child form now increases by a higher ratio. And also the controls appear out of place.
Can anyone suggest a better approach for such situations.
Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将 Parent From isMdiContainer 更改为 true,将子窗体边框样式更改为 none,然后
在 Parent 窗体中在您想要的位置编辑这样的代码。
通过锚点属性编辑控件。
希望它可以对您有所帮助。
Change in Parent From isMdiContainer as true, childform border style as none, then
in Parent form edit code like this in vent where you want.
Edit the Controls to by an Anchor Property.
Hope it may helps to you.
我想你必须使用 ClientRectangle 的宽度和高度而不是 Window 的宽度和高度。因为你的客户端矩形比你的窗口矩形小。这是初步猜测。
I guess you have to use the ClientRectangle's width and height instead of the Window width and height. Because your client rect is smaller than your windows rectangle. This is a initial guess.