简体   繁体   中英

Resizing controls when form is resized

newbie with windows gui programming here. Has Anyone got an idea how to resize controls in a windows form when the form is resized. In wxpython, it was done with the sizers but I cannot seem to find anything similar when developing guis with windows visual c++

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 . 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->Width = 300;
Form1->Height = 300;

inside the event (say, when you click button1). More can be read here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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