Represents a window that represents the user interface of an application.
public class Form: ContainerControl
The following table lists the members exposed by the Form object. Click a tab on the left to choose the type of member you want to view.
Methods
Method Description Activate Activates the form and gives it focus. AdjustFormScrollbars Overriden. Adjusts the auto-scroll bars on the container based on the current control positions and the control currently selected. (Inherited from ContainerControl) BringToFront Brings the control to the front of the z-order. (Inherited from Control) CenterToParent Centers the position of the form within the bounds of the parent form. CenterToScreen Centers the form on the current screen. Close Closes the form. Contains Returns a value indicating whether the specified control is a child of the control. (Inherited from Control) CreateControl Forces the creation of the control, including the creation of the handle and any child controls. (Inherited from Control) CreateControlSkin Creates the skin for the Control. (Inherited from Control) CreateControlSkinInstance Overriden. Creates a ControlSkin instance for the form. CreateControlsInstance Creates a new instance of the control collection for the control. (Inherited from Control) CreateHandle Creates a handle for the control. (Inherited from Control) DestroyHandle Destroys the handle associated with the control. (Inherited from Control) Dispose Overloaded. (Inherited from Component) Equals Overloaded. Compares two objects to determine if they are equal. (Inherited from Object) FindForm Returns the form that the control is on. (Inherited from Control) Focus Sets input focus to the control. (Inherited from Control) Form Initializes a new instance of Form. GetAutoScaleSize Gets the autoscaled sized of the form based on a specified font. GetChildAtPoint Returns the child control that is located at the specified coordinates. (Inherited from Control) GetContainerControl Returns the next ContainerControl up the control's chain of parent controls. (Inherited from Control) GetHashCode Serves as a hash function for a particular type, suitable for use in hashing algorithms and data structures like a hash table. (Inherited from Object) GetNextControl Returns the next control forward or back in the tab order of child controls. (Inherited from Control) GetScrollState Determines whether the specified flag has been set. (Inherited from ScrollableControl) GetStyle Returns the value of the specified control style bit for the control. (Inherited from Control) GetTopLevel Determines if the control is a top-level control. (Inherited from Control) GetType Gets the Type of the current instance. (Inherited from Object) Hide Hides the control from the user. (Inherited from Control) InitLayout Initializes the layout state of the control after it has been added to another container. (Inherited from Control) InternalMethod Inherited from Control. Invalidate Overloaded. Invalidates the control. This will cause a paint event to be sent later to the control. (Inherited from Control) InvokeGotFocus Raises the GotFocus event for the specified control. (Inherited from Control) InvokeLostFocus Raises the LostFocus event for the specified control. (Inherited from Control) InvokeOnClick Raises the Click event for the specified control. (Inherited from Control) InvokePaint Raises the Paint event for the specified control. (Inherited from Control) InvokePaintBackground Invoke the Control.OnPaintBackground method for the specified control. (Inherited from Control) IsInputChar Determines if a character is an input character that the control recognizes. (Inherited from Control) IsInputKey Determines whether the specified key is a regular input key or a special key that requires preprocessing. (Inherited from Control) IsMnemonic Determines if the specified character is the mnemonic character assigned to the control in the specified string. (Inherited from Control) OnActivated Raises the Activated event. OnBackColorChanged Raises the BackColorChanged event. (Inherited from Control) OnCausesValidationChanged Raises the CausesValidationChanged event. (Inherited from Control) OnClick Raises the Click event. (Inherited from Control) OnClientSizeChanged Inherited from Control. OnClosed Raises the Closed event. OnClosing Raises the Closing event. OnControlAdded Raises the ControlAdded event. (Inherited from Control) OnControlRemoved Raises the ControlRemoved event. (Inherited from Control) OnCreateControl Overriden. Raises the CreateControl event. OnCursorChanged Raises the CursorChanged event. (Inherited from Control) OnDeactivate Raises the Deactivate event. OnDockChanged Raises the DockChanged event. (Inherited from Control) OnDoubleClick Raises the DoubleClick event. (Inherited from Control) OnEnabledChanged Raises the EnabledChanged event. (Inherited from Control) OnEnter Raises the Enter event. (Inherited from Control) OnFontChanged Raises the FontChanged event. (Inherited from Control) OnForeColorChanged Raises the ForeColorChanged event. (Inherited from Control) OnGotFocus Raises the GotFocus event. (Inherited from Control) OnHandleCreated Overriden. Raises the HandleCreated event. OnHandleDestroyed Raises the HandleDestroyed event. (Inherited from Control) OnKeyDown Raises the KeyDown event. (Inherited from Control) OnKeyPress Raises the KeyPress event. (Inherited from Control) OnKeyUp Raises the KeyUp event. (Inherited from Control) OnLayout Overriden. Raises the Layout event. (Inherited from ScrollableControl) OnLeave Raises the Leave event. (Inherited from Control) OnLoad Raises the Load event. OnLocationChanged Raises the LocationChanged event. (Inherited from Control) OnLostFocus Raises the LostFocus event. (Inherited from Control) OnMaximumSizeChanged Raises the MaximumSizeChanged event. OnMinimumSizeChanged Raises the MinimumSizeChanged event. OnMouseDown Raises the MouseDown event. (Inherited from Control) OnMouseEnter Raises the MouseEnter event. (Inherited from Control) OnMouseLeave Raises the MouseLeave event. (Inherited from Control) OnMouseMove Raises the MouseMove event. (Inherited from Control) OnMouseUp Raises the MouseUp event. (Inherited from Control) OnMouseWheel Raises the MouseWheel event. (Inherited from Control) OnMove Raises the Move event. (Inherited from Control) OnNCPaint Occurs when the non-client area of the control needs to be redrawn. (Inherited from Control) OnPaint Raises the Paint event. (Inherited from Control) OnPaintBackground Paints the background of the control. (Inherited from Control) OnParentChanged Raises the ParentChanged event. (Inherited from Control) OnParentEnabledChanged Raises the EnabledChanged event when the Enabled property value of the control's container changes. (Inherited from Control) OnParentVisibleChanged Raises the VisibleChanged event when the Visible property value of the control's container changes. (Inherited from Control) OnResize Raises the Resize event. (Inherited from Control) OnScroll Inherited from ScrollableControl. OnSizeChanged Raises the SizeChanged event. (Inherited from Control) OnSkinChanged Raises the SkinChanged event. (Inherited from Control) OnStyleChanged Raises the StyleChanged event. (Inherited from Control) OnTabIndexChanged Raises the TabIndexChanged event. (Inherited from Control) OnTabStopChanged Raises the TabStopChanged event. (Inherited from Control) OnTextChanged Raises the TextChanged event. (Inherited from Control) OnValidated Raises the Validated event. (Inherited from Control) OnValidating Raises the Validating event. (Inherited from Control) OnVisibleChanged Overriden. Raises the VisibleChanged event. (Inherited from ScrollableControl) PerformLayout Overloaded. Forces the control to apply layout logic to all its child controls. (Inherited from Control) PointToClient Computes the location of the specified screen point into client coordinates. (Inherited from Control) PointToScreen Computes the location of the specified client point into screen coordinates. (Inherited from Control) ProcessDialogChar Overriden. Processes a dialog character. ProcessDialogKey Overriden. Processes a dialog key. ProcessMnemonic Overriden. Processes a mnemonic character. (Inherited from ContainerControl) ProcessTabKey Overriden. Selects the next available control in the Form and makes it active. RecreateHandle Forces the re-creation of the handle for the control. (Inherited from Control) RectangleToClient Computes the size and location of the specified screen rectangle in client coordinates. (Inherited from Control) RectangleToScreen Computes the size and location of the specified client rectangle in screen coordinates. (Inherited from Control) ReferenceEquals Determines whether the specified Object instances are the same instance. (Inherited from Object) Refresh Forces the control to invalidate its client area and immediately redraw itself and any child controls. (Inherited from Control) ResetBackColor Resets the BackColor property to its default value. (Inherited from Control) ResetCursor Resets the Cursor property to its default value. (Inherited from Control) ResetFont Resets the Font property to its default value. (Inherited from Control) ResetForeColor Resets the ForeColor property to its default value. (Inherited from Control) ResetSkin Resets the Skin property to its default value. (Inherited from Control) ResetText Resets the Text property to its default value. (Inherited from Control) ResumeLayout Overloaded. Resumes normal layout logic. (Inherited from Control) ScrollControlIntoView Scrolls the specified child control into view on a ScrollableControl object. (Inherited from ScrollableControl) Select Overloaded. Activates the control. (Inherited from Control) SelectNextControl Activates the next control. (Inherited from Control) SendToBack Sends the control to the back of the z-order. (Inherited from Control) SetAutoScrollMargin Sets the size of the auto-scroll margins of the ScrollableControl. (Inherited from ScrollableControl) SetBounds Overloaded. Sets the bounds of the control to the specified location and size. (Inherited from Control) SetBoundsCore Overriden. Performs the work of setting the specified bounds of this Form. SetClientSizeCore Overriden. Sets the size of the client area of the form. SetDisplayRectLocation Sets the display location of the ScrollableControl. (Inherited from ScrollableControl) SetNCSizeCore Sets the non-client area of the control. (Inherited from Control) SetScrollState Sets the specified scroll state flag to the ScrollableControl. (Inherited from ScrollableControl) SetStyle Sets the specified style bit to the specified value. (Inherited from Control) SetTopLevel Sets the control as the top-level control. (Inherited from Control) SetVisibleCore Overriden. Sets the control to the specified visible state. Show Displays the control to the user. (Inherited from Control) ShowDialog Shows the current form as a modal dialog box with no owner window. SuspendLayout Temporarily suspends the layout logic for the control. (Inherited from Control) System.Windows.Forms.IContainerControl.ActivateControl Activates the specified control. (Inherited from ContainerControl) ToString Returns a String that represents the current Object. (Inherited from Object) Update Causes the control to redraw its client area if it was invalidated. (Inherited from Control) UpdateBounds Overloaded. Updates the bounds of the control with the current size and location. (Inherited from Control) UpdateDefaultButton Overriden. Updates the button which is the default button. UpdateZOrder Updates the control in its parent's z-order. (Inherited from Control) Validate Validates the last invalidated control and its ancestors up through, but not including, the current control. (Inherited from ContainerControl) Properties
Property Description AcceptButton Gets or sets the button that is clicked when the ENTER key is pressed. ActiveControl Gets or sets the active control on the container control. (Inherited from ContainerControl) ActiveForm Gets the currently active form for this application. Anchor Gets or sets which edges of the control are anchored to the edges of its container. (Inherited from Control) AutoScaleBaseSize Gets or sets the base size used for autoscaling the Form. AutoScroll Gets or sets a value indicating whether the container will allow the user to scroll to any controls placed outside of its visible boundaries. (Inherited from ScrollableControl) AutoScrollMargin Gets or sets the size of the auto-scroll margin. (Inherited from ScrollableControl) AutoScrollMinSize Gets or sets the minimum size of the auto-scroll. (Inherited from ScrollableControl) AutoScrollPosition Gets or sets the location of the auto-scroll position. (Inherited from ScrollableControl) BackColor Gets or sets the background color for the control. (Inherited from Control) BackVisual Gets the visual of the control. (Inherited from Control) Bottom Gets the distance between the bottom edge of the control and the top edge of its container's client area. (Inherited from Control) Bounds Gets or sets the size and location of the control including its nonclient elements. (Inherited from Control) CanFocus Gets a value indicating whether the control can receive focus. (Inherited from Control) CanSelect Gets a value indicating whether the control can be selected. (Inherited from Control) CancelButton Gets or sets the button that is clicked when the ESC key is pressed. Capture Gets or sets a value indicating whether the control has captured the mouse. (Inherited from Control) CausesValidation Gets or sets a value indicating whether the control causes validation for any controls that require validation when it receives focus. (Inherited from Control) ClientRectangle Gets the rectangle that represents the client area of the control. (Inherited from Control) ClientSize Gets or sets the height and width of the client area of the control. (Inherited from Control) Container Gets the IContainer that contains the Component. (Inherited from Component) ContainsFocus Gets a value indicating whether the control or one of its child controls currently has the input focus. (Inherited from Control) ControlSkin Gets the ControlSkin of the control. (Inherited from Control) Controls Gets the collection of controls contained within the control. (Inherited from Control) Created Gets a value indicating whether the control has been created. (Inherited from Control) Cursor Gets or sets the cursor which is displayed when the mouse pointer is over the control. (Inherited from Control) DefaultBackColor Gets the default background color of the control. (Inherited from Control) DefaultFont Gets the default font of the control. (Inherited from Control) DefaultForeColor Gets the default foreground color of the control. (Inherited from Control) DefaultSize Overriden. Gets the default size of the Form. DefaultSkin Gets or sets the default skin of the control. (Inherited from Control) DialogResult Gets or sets the dialog result for the Form. DisplayRectangle Overriden. Gets the rectangle which represents the display area of the ScrollableControl. (Inherited from ScrollableControl) Disposing Gets a value indicating whether the control is in the process of being disposed of. (Inherited from Control) Dock Gets or sets which edge of the parent container a control is docked to. (Inherited from Control) DockPadding Gets the dock padding settings for all edges of the ScrollableControl. (Inherited from ScrollableControl) Enabled Gets or sets a value indicating whether the control can react to user interaction. (Inherited from Control) Focused Gets a value indicating whether the control has input focus. (Inherited from Control) Font Gets or sets the font of the text which is displayed by the control. (Inherited from Control) ForeColor Gets or sets the foreground color of the control. (Inherited from Control) FormBorderStyle Gets or sets the border style of the Form. HScroll Gets or sets a value indicating whether the horizontal scroll bar of the ScrollableControl is visible. (Inherited from ScrollableControl) Handle Gets the native handle that the control is bound to. (Inherited from Control) HasChildren Gets a value indicating whether the control has one or more child controls. (Inherited from Control) Height Gets or sets the height of the control. (Inherited from Control) IsDisposed Gets a value indicating whether the control has been disposed of. (Inherited from Control) IsHandleCreated Gets a value indicating whether the control has a handle associated with it. (Inherited from Control) Left Gets or sets the horizontal coordinate of a control's left edge. (Inherited from Control) Location Gets or sets the coordinates of the upper-left corner of the control relative to the upper-left corner of its container. (Inherited from Control) MaskVisual Gets the Visual which is the mask of the control. (Inherited from Control) MaximumSize Gets or sets the maximum size the Form can be resized to. MinimumSize Gets or sets the minimum size the Form can be resized to. Modal Gets a value indicating whether this Form is modal form. ModifierKeys Gets a value indicating when one of the modifier keys (SHIFT, CTRL, and ALT) is pressed. (Inherited from Control) MouseButtons Gets a value indicating when one of the mouse buttons is clicked. (Inherited from Control) MousePosition Gets the position of the mouse cursor in global coordinates. (Inherited from Control) NCVisual Gets the non-client visual element of the control. (Inherited from Control) Name Gets or sets the name of the control. (Inherited from Control) OverlayVisual Gets a visual placed over everything. (Inherited from Control) Owner Gets the form that owns this Form. Parent Gets or sets the parent container of the control. (Inherited from Control) ParentForm Gets the form that the container control is assigned to. (Inherited from ContainerControl) Parked Gets a value indicating whether the control is parked. (Inherited from Control) RecreatingHandle Gets a value indicating whether the control is currently re-creating its handle. (Inherited from Control) Right Gets the distance between the right edge of the control and the left edge of its container. (Inherited from Control) Site Gets or sets the ISite of the Component. (Inherited from Component) Size Gets or sets the height and width of the control. (Inherited from Control) Skin Gets or sets the skin of the control. (Inherited from Control) StartPosition Gets or sets the starting position of the Form at run time. SystemMenu Gets or sets the SystemMenu of the control. (Inherited from Control) TabIndex Gets or sets the tab order of the control within its container. (Inherited from Control) TabStop Gets or sets a value indicating whether the user can use the TAB key to focus to the control. (Inherited from Control) Tag Gets or sets the object that contains data about the control. (Inherited from Control) Text Overriden. Gets or sets the text which is associated with the Form. Top Gets or sets the vertical coordinate of the control's top edge. (Inherited from Control) TopLevel Gets or sets a value indicating whether the Form is displayed as a top-level window. TopLevelControl Gets the parent control that is not parented by another Windows Forms control. (Inherited from Control) TopMost Gets or sets a value indicating whether the Form is displayed as a topmost window. VScroll Gets or sets a value indicating whether the vertical scroll bar of the ScrollableControl is visible. (Inherited from ScrollableControl) Visible Gets or sets a value indicating whether the control is visible. (Inherited from Control) Visual Gets the visual element of the control. (Inherited from Control) Width Gets or sets the width of the control. (Inherited from Control) Events
Event Description Activated Handles the activation of the Form. BackColorChanged Handles the changes of the BackColor property. (Inherited from Control) CausesValidationChanged Handles the changes of the CausesValidation property. (Inherited from Control) Click Handles the click event when the control is clicked. (Inherited from Control) ClientSizeChanged Inherited from Control. Closed Handles the closure of the Form. Closing Handles the closing of the Form. ControlAdded Handles the addition of a new control when it is added to the Control.ControlCollection. (Inherited from Control) ControlRemoved Handles the remove of a control from the Control.ControlCollection. (Inherited from Control) CursorChanged Handles the changes of the Cursor property. (Inherited from Control) Deactivate Handles the deactivation of the Form. Disposed Adds an event handler to listen to the Disposed event on the component. (Inherited from Component) DockChanged Handles the changes of the Dock property. (Inherited from Control) DoubleClick Handles the double-clicked event of the control. (Inherited from Control) EnabledChanged Handles the changes of the Enabled property. (Inherited from Control) Enter Handles the entered event of the control. (Inherited from Control) FontChanged Handles the changes of the Font property. (Inherited from Control) ForeColorChanged Handles the changes of the ForeColor property. (Inherited from Control) GotFocus Handles the focus reception of the control. (Inherited from Control) HandleCreated Handles the creation of a handle for the control. (Inherited from Control) HandleDestroyed Handles the control's handle which is in the process of being destroyed. (Inherited from Control) KeyDown Handles the pressed key event when a key is pressed and the control has focus. (Inherited from Control) KeyPress Handles the pressed key event when a key is pressed and the control has focus. (Inherited from Control) KeyUp Handles the release key event when a key is released and the control has focus. (Inherited from Control) Layout Handles the changes of control when it should reposition its child controls. (Inherited from Control) Leave Handles the input focus when it leaves the control. (Inherited from Control) Load Handles the loading of the Form. LocationChanged Handles the changes of the Location property. (Inherited from Control) LostFocus Handles the focus on the control when it loses focus. (Inherited from Control) MaximumSizeChanged Handles the changes of the MaximumSize property. MinimumSizeChanged Handles the changes of the MinimumSize property. MouseDown Handles the mouse event when the mouse pointer is over the control and a mouse button is pressed. (Inherited from Control) MouseEnter Handles the mouse event when the mouse pointer enters the control. (Inherited from Control) MouseLeave Handles the mouse event when the mouse pointer leaves the control. (Inherited from Control) MouseMove Handles the mouse event when the mouse pointer is moved over the control. (Inherited from Control) MouseUp Handles the mouse event when the mouse pointer is over the control and a mouse button is released. (Inherited from Control) MouseWheel Handles the mouse event when the mouse wheel moves while the control has focus. (Inherited from Control) Move Handles the motion of the control when it is moved. (Inherited from Control) Paint Handles the paint event of the control when it is redrawn. (Inherited from Control) ParentChanged Handles the changes of the Parent property. (Inherited from Control) Resize Handles the size changes of the control when it is resized. (Inherited from Control) Scroll Inherited from ScrollableControl. SizeChanged Handles the changes of the Size property. (Inherited from Control) SkinChanged Handles the changes of the Skin property. (Inherited from Control) StyleChanged Handles the changes of the control style. (Inherited from Control) TabIndexChanged Handles the changes of the TabIndex property. (Inherited from Control) TabStopChanged Handles the changes of the TabStop property. (Inherited from Control) TextChanged Handles the changes of the Text property. (Inherited from Control) Validated Handles the validation of the control when it is finished validating. (Inherited from Control) Validating Handles the validation of the control when it is validating. (Inherited from Control) VisibleChanged Determines the value of the VScroll property. (Inherited from Control) Constants
Constant Description ScrollState_AutoScrolling Determines the value of the AutoScroll property. (Inherited from ScrollableControl) ScrollState_HScrollVisible Determines the value of the HScroll property. (Inherited from ScrollableControl) ScrollState_UserHasScrolled Determines whether the user has scrolled the ScrollableControl. (Inherited from ScrollableControl) ScrollState_VScrollVisible Determines the value of the VScroll property. (Inherited from ScrollableControl)
Object
// This sample shows how to create a Form.
using System;
using System.Drawing;
using System.Windows.Forms;
public class MyForm: Form
{
private Button button1;
private CheckBox checkbox1;
private RadioButton rb1;
private RadioButton rb2;
private Label label1;
private HScrollBar hsb1;
private VScrollBar vsb1;
private TextBox tb2;
private Link link2;
private Label label2;
private TextBox tb1;
private ScrollableControl sc;
private GroupBox gb;
public MyForm()
{
InitializeComponent();
}
private void InitializeComponent()
{
int x= 30;
int y= 35;
const int m= 5;
button1= new Button();
button1.Location= new Point(x
,y);y+= 30;
checkbox1= new CheckBox();
checkbox1.Location= new Point(x,y);
rb1= new RadioButton();
rb1.Location= new Point(x,y);
rb2= new RadioButton();
rb2.Location= new Point(x,y);
label1= new Label();
label1.Location= new Point(x,y);
label1.Text= "This is a sample label";
hsb1= new HScrollBar();
hsb1.Location= new Point(x,10);
vsb1= new VScrollBar();
vsb1.Location= new Point(5,30);
tb2= new TextBox();
tb2.Location= new Point(x,y);
link2= new Link();
link2.Location= new Point(x,y);
label2= new Label();
label2.Location= new Point(x,y);
label2.Text= "A Multiline Text Box:";
tb1= new TextBox();
tb1.Location= new Point(x,y);
tb1.Text= "Line 1 starts this textbox.\nLine 2\nLine 3\nLine 4\nLine 5\nLine 6\nLine 7\nLine 8\nLine 9 \nLine A\nLine B\nLine C\nLine D end";
tb1.ScrollBars= ScrollBars.Both;
y+= 30;
gb= new GroupBox();
gb