Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Visual Studio C#2019中调整控件以匹配窗体大小?_C#_Visual Studio 2019 - Fatal编程技术网

在Visual Studio C#2019中调整控件以匹配窗体大小?

在Visual Studio C#2019中调整控件以匹配窗体大小?,c#,visual-studio-2019,C#,Visual Studio 2019,通常,当我缩小我的表格时,它只是掩盖了一些东西。如何使内容在调整窗体大小时调整位置 这个问题的唯一答案来自9-10年前,指的是我找不到的房产 编辑:我想我可能没有使用winforms,具体的项目类型是“Windows Forms App(.NET Framework),这不是winforms吗?调整窗体大小时,可以创建一个新类来调整控件的位置 public partial class Form1 : Form { AutoSizeFormClass asc = new

通常,当我缩小我的表格时,它只是掩盖了一些东西。如何使内容在调整窗体大小时调整位置

这个问题的唯一答案来自9-10年前,指的是我找不到的房产


编辑:我想我可能没有使用winforms,具体的项目类型是“Windows Forms App(.NET Framework),这不是winforms吗?

调整窗体大小时,可以创建一个新类来调整控件的位置

public partial class Form1 : Form
    {

        AutoSizeFormClass asc = new AutoSizeFormClass();
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            asc.controllInitializeSize(this);
        }

        private void Form1_SizeChanged(object sender, EventArgs e)
        {
            asc.controlAutoSize(this);
        }
    }
    class AutoSizeFormClass
    {  
        public struct controlRect
        {
            public int Left;
            public int Top;
            public int Width;
            public int Height;
        }
        public List<controlRect> oldCtrl;
        public void controllInitializeSize(Form mForm)
        {
                oldCtrl = new List<controlRect>();
                controlRect cR;
                cR.Left = mForm.Left; cR.Top = mForm.Top; cR.Width = mForm.Width; cR.Height = mForm.Height;
                oldCtrl.Add(cR);
                foreach (Control c in mForm.Controls)
                {
                    controlRect objCtrl;
                    objCtrl.Left = c.Left; objCtrl.Top = c.Top; objCtrl.Width = c.Width; objCtrl.Height = c.Height;
                    oldCtrl.Add(objCtrl);
                }

        }
        public void controlAutoSize(Form mForm)
        { 
            float wScale = (float)mForm.Width / (float)oldCtrl[0].Width; 
            float hScale = (float)mForm.Height / (float)oldCtrl[0].Height;
            int ctrLeft0, ctrTop0, ctrWidth0, ctrHeight0;
            int ctrlNo = 1;
            foreach (Control c in mForm.Controls)
            {
                ctrLeft0 = oldCtrl[ctrlNo].Left;
                ctrTop0 = oldCtrl[ctrlNo].Top;
                ctrWidth0 = oldCtrl[ctrlNo].Width;
                ctrHeight0 = oldCtrl[ctrlNo].Height;
                c.Left = (int)((ctrLeft0) * wScale);
                c.Top = (int)((ctrTop0) * hScale); 

                ctrlNo += 1;
            }
        }

    }
公共部分类表单1:表单
{
AutoSizeFormClass asc=新的AutoSizeFormClass();
公共表格1()
{
初始化组件();
}
私有void Form1\u加载(对象发送方、事件参数e)
{
asc.控制器初始化(此);
}
private void Form1\u SizeChanged(对象发送方,事件参数e)
{
asc.controlAutoSize(此);
}
}
类AutoSizeFormClass
{  
公共结构controlRect
{
公共int左;
公共int Top;
公共整数宽度;
公众内部高度;
}
公共列表;
public void controllerInitializeSize(表单mForm)
{
oldCtrl=新列表();
controlRect cR;
cR.Left=mForm.Left;cR.Top=mForm.Top;cR.Width=mForm.Width;cR.Height=mForm.Height;
oldCtrl.Add(cR);
foreach(mForm.Controls中的控件c)
{
controlRect objCtrl;
objCtrl.Left=c.Left;objCtrl.Top=c.Top;objCtrl.Width=c.Width;objCtrl.Height=c.Height;
oldCtrl.Add(objCtrl);
}
}
公共void controlAutoSize(表单mForm)
{ 
float wScale=(float)mForm.Width/(float)oldCtrl[0]。宽度;
float hScale=(float)mForm.Height/(float)oldCtrl[0]。Height;
int-ctrLeft0、ctrTop0、ctrWidth0、ctrHeight0;
int ctrlNo=1;
foreach(mForm.Controls中的控件c)
{
ctrLeft0=oldCtrl[ctrlNo]。左;
ctrTop0=oldCtrl[ctrlNo]。顶部;
ctrWidth0=oldCtrl[ctrlNo]。宽度;
ctrHeight0=oldCtrl[ctrlNo]。高度;
c、 左=(int)((ctrLeft0)*wScale);
c、 Top=(int)((ctrTop0)*hs刻度);
ctrlNo+=1;
}
}
}
测试结果:


这回答了你的问题吗?-是的,大约9年前,情况仍然如此。你确定你在使用Winforms吗?你找不到什么属性?哦,顺便说一句,
TableLayoutPanel
FlowLayoutPanel
都是控件。”这个问题的唯一答案是9-10年前的“与此同时,更现代的GUI框架,如WPF和不同形式的应用程序(例如,单页Web应用程序…)已变得更加普遍。WinForms是一项相当古老的技术,因此任何问题和答案都可能相当过时。如果您坚持使用WinForms,那么对于任何比“hello world”应用程序更复杂的应用程序,您都需要学习如何使用。从这些评论中,我感觉我使用的不是WinForms。是的,这就是WinForms。在设计器中,如果单击TextBox控件,您应该会看到名为锚定或停靠等的属性。请适当设置它们。