使用窗体调整大小调整控件 [英] Resize Controls with Form Resize

查看:75
本文介绍了使用窗体调整大小调整控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了几个堆栈溢出问题,但没有找到解决我问题的有效方法。每当调整窗体大小时,如何调整控件大小?我希望它们在窗体变大或变小时变大或变小。

I have read several stack overflow questions without finding a good working solution to my problem. How can I resize my controls whenever the form is resized? I would like them to get larger or smaller when the form becomes larger or smaller.

在Visual Basic中,使用form.Zoom属性很容易做到这一点(当然并不是真的需要调整控件的大小,而是解决了我所需要的)。不幸的是,这在C#winforms中不可用。

In visual basic this was quite easy to do with the form.Zoom property (which did't really require resizing controls of course, but solved what I needed). Unfortunately this is not available in C# winforms.

以下是我尝试过没有运气的其他事情:

Here is some other things I have tried without luck:

private void formMain_Resize(object sender, EventArgs e)
{/*
double scale;
this.scaleWidth = (float)this.Width / (float)this.origWidth;
this.scaleHeight = (float)this.Height / (float)this.origHeight;
if (this.scaleHeight > this.scaleWidth)
{
    scale = this.scaleHeight;
}
else
{
    scale = this.scaleWidth;
}

foreach (Control control in this.Controls)
{
    control.Height = (int)(control.Height * this.scaleHeight);
    control.Width = (int)(control.Width * this.scaleWidth);
    this.Refresh();
    //  control.Font = new Font("Verdana", control.Font.SizeInPoints * heightRatio * widthRatio);
}
///////This scaling didnt work for me either
//this.Scale(new SizeF(this.scaleWidth, this.scaleHeight));
//this.Refresh();
*/
}

如果我实际上忽略了工作关于另一个堆栈溢出问题的代码示例,我很想看看,但是我发现的类似于上面无法使用的代码。

If I overlooked an actualy working sample of code on another stack overflow question I would love to see it, but the ones I found were similar to those above which are not working.

也许我被滥用,有人可以发布示例代码来向那些不断问这个问题如何解决问题的人展示。

Perhaps I was misusing it and someone could post sample code to show for those of us who keep asking this question how to go about solving the problem.

此外,我尝试使用一些锚/停靠工具中的一部分认为它们会自动允许它,但不允许这样做。

Also, I have tried using some of the anchor/docking tools thinking they would automatically allow it but it didn't.

推荐答案

我找到了一个替代解决方案对于我来说运作良好,请对解决方案提出任何负面或正面的评价。

I found an alternative solution that is working well for me, appreciate any negative or positive comments on the solution.

在不同地区的拆分容器中使用多个拆分容器和拆分容器,我可以进行剖析布局的主要部分,并在其中使用Docking和Anchoring,我能够完全完成我想做的事情-它可以工作b

Using several Split Containers and Split Containers inside of Split Containers in different regions I am able to section off the primary pieces of the layout, and within there utilizing Docking and Anchoring I am able to accomplish exactly what I wanted to do - it works beautifully.

我要指出的是,我知道有些在线的人提到拆分容器使用大量资源。

I would point out I am aware that some folks online mention split containers use lots of resources.

这篇关于使用窗体调整大小调整控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆