70-526 MCTSLayoutThe layout of a form can be affected in many ways AutoScaleModeThe default value is set to None although the IDE sets the default to Font for a new Form. This property specifies the current automatic scaling mode of the Form and takes a value from the AutoScaleMode enumeration: To change the AutoScaleMode property at run time, simply set the property to the desired value. this.AutoScaleMode = AutoScaleMode.Font; AutoScrollThe default value is set to False. This property indicates whether the form enables autoscrolling. When you set this property is true, scroll bars are displayed on the form when any controls are located outside of the form's client region. Also, the client area of the form automatically scrolls to make the control with input focus visible. ![]() To change the AutoScroll property at run time, simply set the property to the desired value. Form1.AutoScroll = true; AutoScrollMarginThe default value is set to 0,0. This property is the distance between any child controls and the edges of the scrollable parent control. When determining whether or not scroll bars are needed, the AutoScrollMargin size is added to the size of any child controls contained in the scrollable control. Docked controls are excluded from the calculations that determine if scroll bars must be displayed. To change the AutoScrollMargin property at run time, use the SetAutoScrollMargin method. Form1.SetAutoScrollMargin(5, 5); AutoScrollMinSizeThe default value is set to 0,0. This property determines the minimum size of the area in the form through which the user can scroll. For example, if AutoScrollMinSize is set to 300,200, then anytime that either the height is smaller than 200 or the width is smaller than 300, then the scroll bars will appear. (Technically the scroll bars appear anytime that the width is AutoScrollMinSize.Width - scrollbar.width or anytime that the height is AutoScrollMinSize.Height - scrollbar.height). To change the AutoScrollMinSize property at run time, set the property to a new instance of the Size structure: this.AutoScrollMinSize = new Size (10, 20); AutoSizeThe default value is set to False. This property resizes the form according to the setting of AutoSizeMode. When set to true, the form will automatically resize to fit its contents. Note To change the AutoSize property at run time, simply set the property to the desired value. this.AutoSize = true; AutoSizeModeThe default value is set to GrowOnly. This property determines the mode by which the form automatically resizes itself and takes a value from the AutoSizeMode enumeration: To change the AutoSizeMode property at run time, simply set the property to the desired value. this.AutoSizeMode = AutoSizeMode.GrowAndShrink; LocationThe default value is set to 0,0. This property determines the position on the screen when StartPosition is set to Manual. Note To change the Location property at run time, set the property to a new instance of the Point structure: this.Location = new System.Drawing.Point (100, 100); MaximumSizeThe default value is set to 0,0. This property determines the maximum size the form can be resized to. To change the MaximumSize property at run time, set the property to a new instance of the Size structure: this.MaximumSize = new Size(500, 500); MinimumSizeThe default value is set to 0,0. This property determines the minimum size the form can be resized to. To change the MinimumSize property at run time, set the property to a new instance of the Size structure: this.MinimumSize = new Size(200, 200); PaddingThe default value is set to 0, 0, 0, 0 and is inherited from Control. This property represents the control's internal spacing characteristics. Controls receive default values for Padding that are reasonably close to Windows user interface guidelines. The padding is the internal space between the body of the UI element and its edge. A useful diagram explaining this can be found on MSDN - Margin and Padding in Windows Forms Controls. To change the Padding property at run time, set the property to a new instance of the Padding structure: this.Padding = new System.Windows.Forms.Padding(5); SizeThe default value is set to 300,300. This property gets or sets the size of the form and is an instance of the Size structure. This property allows you to set both the height and width (in pixels) of the form at the same time instead of setting the Height and Width properties individually. To change the Size property at run time, set the property to a new instance of the Size structure: Form1.Size = new Size(600,500); Note The size of the form can also be altered at run time by grabbing and dragging any part of the border of the form. StartPositionThe default value is set to WindowsDefaultLocation. This property determines the initial position of the form when it is first displayed and takes a value from the FormStartPosition enumeration: To change the StartPosition property at run time, simply set the property to the desired value. this.StartPosition = FormStartPosition.CenterScreen; WindowStateThe default value is set to Normal. This property represents the window state of the Form and takes a value from the FormWindowState enumeration: By setting a value other than Normal in the Properties Window of the IDE, this will dictate the state of the Form when the Form first opens. To change the WindowState property at runtime, simply set the property to the desired value. Form1.WindowState = FormWindowState.Minimized; or Form1.WindowState = FormWindowState.Maximized; DesktopBoundsThis property is not located in the Properties Window of the IDE.If you want to set the size and location of a form, you can use the DesktopBounds property to size and locate the form based on desktop coordinates or use the Bounds property of the Control class to set the size and location of the form based on screen coordinates. For example, to set the size of the form to 400 wide and 400 high and the position of a form so that the form is positioned 50 pixels from the left border of the desktop and 50 pixels from the top of the desktop you would use the following code: // Create a Rectangle object that will be used as the bound of the form. Rectangle tempRect = new Rectangle(50,50,400,400); // Set the bounds of the form using the Rectangle object. this.DesktopBounds = tempRect; Note MSDN references
|