缩放窗口形式的窗口 [英] Scale windows forms window

查看:142
本文介绍了缩放窗口形式的窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有可能准备Windows窗体窗口,以调整/复位根据窗口大小的所有元素,但我尝试做不同的东西。

It is possible to prepare the windows forms window to resize/reposition all elements depending on the window size, but I am trying to do something different.

它是可能以某种方式实际上所有的元素一起缩放窗口内,无论它们的位置,属性等?

Is it possible in some way to actually scale the window along with all elements inside regardless of their positions, properties, etc?

基本上你的方式将缩减在某些图形编辑器的图片 - 你可以拉伸或收缩,但它并不重要的是在该图片

Basically the way you would scale a picture in some graphics editor - you can just stretch or shrink it, but it doesn't matter what is on that picture.

那么,是不是可以做的形式类似的东西?能够不管形式里面有什么规模的大小。

So, is it possible to do something similar with the form? Being able to scale its size regardless of what's inside the form.

推荐答案

Windows窗体不提供任何功能来做到这一点。但是,你可以编写自己的代码,进行独立的表单解决方案。

Windows form does not provide any feature to do this. But, you can write your own code and make your form resolution independent.

这是不是一个完整的例子来进行独立的windows窗体的分辨率,但是,你可以从这里得到的逻辑。当您快速调整窗口下面的代码创建的问题。

This is not a complete example to make windows form resolution independent but, you can get logic from here. The following code creates problem when you resize the window quickly.

代码:

private Size oldSize;
private void Form1_Load(System.Object sender, System.EventArgs e)
{
    oldSize = base.Size;
}
protected override void OnResize(System.EventArgs e)
{
    base.OnResize(e);
    foreach (Control cnt in this.Controls) {
        ResizeAll(cnt, base.Size);
    }
    oldSize = base.Size;
}
private void ResizeAll(Control cnt, Size newSize)
{
    int iWidth = newSize.Width - oldSize.Width;
    cnt.Left += (cnt.Left * iWidth) / oldSize.Width;
    cnt.Width += (cnt.Width * iWidth) / oldSize.Width;

    int iHeight = newSize.Height - oldSize.Height;
    cnt.Top += (cnt.Top * iHeight) / oldSize.Height;
    cnt.Height += (cnt.Height * iHeight) / oldSize.Height;
}



否则,你可以使用任何第三方控件一样的 DevExpress的工具。有 LayoutControl 它提供相同的服务。您可以显示和隐藏在运行时不留空白的控制。

Otherwise you can use any third party control like DevExpress Tool. There is LayoutControl which is providing same facility. you can show and hide any control at runtime without leaving blank space.

这篇关于缩放窗口形式的窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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