简体   繁体   English

调整窗体大小时调整控件的大小

[英]Resizing controls when form is resized

newbie with windows gui programming here. Windows gui编程的新手在这里。 Has Anyone got an idea how to resize controls in a windows form when the form is resized. 有谁知道如何在调整窗体大小时调整Windows窗体中控件的大小。 In wxpython, it was done with the sizers but I cannot seem to find anything similar when developing guis with windows visual c++ 在wxpython中,它是由sizer完成的,但是在使用Windows visual c ++开发guis时,我似乎找不到类似的东西

A control has a member called "Anchor". 控件具有一个称为“锚点”的成员。 You can see it from the editor. 您可以从编辑器中看到它。 If you want the object to keep its positioning in all four corners of it's rectangle you can simply enable all of the sub properties under Anchor. 如果要使对象保持在矩形所有四个角的位置,可以简单地启用“锚点”下的所有子属性。

You can read more about the member here: Microsoft.com/Anchor . 您可以在此处阅读有关该成员的更多信息: Microsoft.com/Anchor If you want to dynammicly enable the properties of an control you can simply use this example: 如果要动态启用控件的属性,则可以使用以下示例:

Control.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top |   System.Windows.Forms.AnchorStyles.Bottom) 
        | System.Windows.Forms.AnchorStyles.Left) 
        | System.Windows.Forms.AnchorStyles.Right)));

I managed to change it from Form1.h using 我设法使用以下方法从Form1.h进行了更改

Form1->Width = 300;
Form1->Height = 300;

inside the event (say, when you click button1). 在事件内部(例如,当您单击button1时)。 More can be read here . 在这里可以阅读更多内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM