How do I get controls to resize properly using C#?
So I've created a new C# Windows Form, I'm using the Gecko Web Browser control and I want the browser to resize with the rest of my program开发者_运维问答 (stretching or shrinking) as opposed to the "white space" of the program (the navigation bar, etc.) to resize. How might I cause the control to resize with the rest of the program?
If you just want the control to grow proportionally to it's original size (as opposed to DockStyle.Fill
which will take up the entire area), you can use the Anchor
property. If you set the web browser control to be anchored Top, Left, Bottom and Right, then it will grow and shrink as the form is resized. It's probably easiest to set it from the Visual Designer but if you want to do it via code you can use:
geckoWebBrowser.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
in the control's property set the dock to fill
geckoWebBrowser.Dock = DockStyle.Fill;
精彩评论