Form

Form marshal by reference, disposable

System. Windows .Forms (system. windows .forms.dll) class

A Form is a specialization of Control that supports top-level windows such as tool windows, frame windows, application pop-ups, and MDI child windows.

The appearance of the form's non-client imagery can be set using the FormBorderStyle to determine the basic appearance, along with the SizeGripStyle to determine whether to show the resizing grippy. The non-client controls are enabled and disabled with the ControlBox (which enables the system menu and close button), MaximizeBox , MinimizeBox , and HelpButton properties. You can also set the Icon to use for the ControlBox .

The Form can also show a Menu , and a MergedMenu can be retrieved for the current context if you are using the MDI idiom.

You can create and Show() a form modelessly as with any other control, or use the ShowDialog() method to create and show a modal window. The Modal property can be used to determine which method is used to display the form. How the Form is initially positioned is determined by the StartPosition property. You can subsequently minimize or maximize the form by setting the WindowState . It will float above all other windows if you set TopMost to true. While it is showing, it can be made to appear in the taskbar by setting the ShowInTaskbar property.

When the Form is closed, the ShowDialog() method returns the DialogResult .

Default button processing is handled through the AcceptButton and CancelButton properties. You can assign any IButtonControl -derived class to this property (which includes Button and LinkLabel , for example). When the button is clicked, it will close the window, setting the DialogResult property appropriately.

Normally, a Form cannot be contained by another control. There are two exceptions to this rule. MDI support is provided through the MdiParent property. If you host a Form in another by setting its MdiParent , it will appear in the containing Form objects MdiChildren array, and the ActiveMdiChild can also be retrieved. Alternatively, you can set the TopLevel property to false to allow you to embed the form in another ContainerControl . Note that if the control has MdiChildren , TopLevel must remain set to true. You can tile or stack the MdiChildren by calling the LayoutMdi() method.

Unlike Win32, there are two separate, well-defined Form hierarchies: the Parent , which determines containment relationships of non-toplevel objects (as with all Control objects), and the Owner , which determines the message routing and ownership hierarchy of toplevel windows. For example, a Form object should be the Owner of its pop-up tool windows, dialogs, etc.

The Form has the ability to intercept keyboard messages destined for its child controls. You can set the KeyPreview property to true, and then receive KeyPress , KeyUp , and KeyDown events that would normally (and will eventually) be sent to a child.

A Form can automatically resize itself and scale its contained controls when the Font size changesthe same kind of behavior as Win32 dialogs, only without the horrible complexities of dialog units to pixel mapping. This is enabled using the AutoScale property. Before you show the Form , you can set the AutoScaleBaseSize to specify the size of the default Font . The designer environment will set this property for you, but if you need to do it yourself, you should set it to the font's em-height and average character width. While on the subject of sizing, you can specify a MinimumSize and a MaximumSize , and you can get the DesktopBounds and DesktopLocation , in addition to the standard Location and Bounds .

Finally, you can support transparent forms in two ways. You can set the overall Opacity of the form (1.00 is completely opaque , and 0.00 is completely transparent, with 0.50 partially transparent). Note that this is different to the 0-255 range for the alpha value of System.Drawing. Color objects. Alternatively, you can set a TransparencyKey for a simple chroma-key effect. Any pixel painted in that System.Drawing.Color will become transparent. Note that the transparency features are supported only on Windows 2000 and above, and there is absolutely no per-pixel alpha transparency support.

 public class  Form  : ContainerControl {  // Public Constructors  public  Form  ();  // Public Static Properties  public static Form  ActiveForm  {get; }  // Public Instance Properties  public IButtonControl  AcceptButton  {set; get; }    public Form  ActiveMdiChild  {get; }    public bool  AllowTransparency  {set; get; }    public bool  AutoScale  {set; get; }    public virtual Size  AutoScaleBaseSize  {set; get; }    public override bool  AutoScroll  {set; get; }  // overrides ScrollableControl  public override Color  BackColor  {set; get; }  // overrides Control  public IButtonControl  CancelButton  {set; get; }    public Size  ClientSize  {set; get; }  // overrides Control  public bool  ControlBox  {set; get; }    public Rectangle  DesktopBounds  {set; get; }    public Point  DesktopLocation  {set; get; }    public DialogResult  DialogResult  {set; get; }    public FormBorderStyle  FormBorderStyle  {set; get; }    public bool  HelpButton  {set; get; }    public Icon  Icon  {set; get; }    public bool  IsMdiChild  {get; }    public bool  IsMdiContainer  {set; get; }    public bool  IsRestrictedWindow  {get; }    public bool  KeyPreview  {set; get; }    public bool  MaximizeBox  {set; get; }    public Size  MaximumSize  {set; get; }    public Form[ ]  MdiChildren  {get; }    public Form  MdiParent  {set; get; }    public MainMenu  Menu  {set; get; }    public MainMenu  MergedMenu  {get; }    public bool  MinimizeBox  {set; get; }    public Size  MinimumSize  {set; get; }    public bool  Modal  {get; }    public double  Opacity  {set; get; }    public Form[ ]  OwnedForms  {get; }    public Form  Owner  {set; get; }    public bool  ShowInTaskbar  {set; get; }    public Size  Size  {set; get; }  // overrides Control  public SizeGripStyle  SizeGripStyle  {set; get; }    public FormStartPosition  StartPosition  {set; get; }    public int  TabIndex  {set; get; }  // overrides Control  public bool  TopLevel  {set; get; }    public bool  TopMost  {set; get; }    public Color  TransparencyKey  {set; get; }    public FormWindowState  WindowState  {set; get; }  // Protected Instance Properties  protected override CreateParams  CreateParams  {get; }  // overrides ContainerControl  protected override ImeMode  DefaultImeMode  {get; }  // overrides Control  protected override Size  DefaultSize  {get; }  // overrides Control  protected Rectangle  MaximizedBounds  {set; get; }  // Public Static Methods  public static SizeF  GetAutoScaleSize  (System.Drawing.Font  font  );  // Public Instance Methods  public void  Activate  ();    public void  AddOwnedForm  (Form  ownedForm  );    public void  Close  ();    public void  LayoutMdi  (MdiLayout  value  );    public void  RemoveOwnedForm  (Form  ownedForm  );    public void  SetDesktopBounds  (int  x  , int  y  , int  width  , int  height  );    public void  SetDesktopLocation  (int  x  , int  y  );    public DialogResult  ShowDialog  ();    public DialogResult  ShowDialog  (IWin32Window  owner  );    public override string  ToString  ();  // overrides System.ComponentModel.Component   // Protected Instance Methods  protected void  ActivateMdiChild  (Form  form  );    protected override void  AdjustFormScrollbars  (bool  displayScrollbars  );  // overrides ContainerControl  protected void  ApplyAutoScaling  ();    protected void  CenterToParent  ();    protected void  CenterToScreen  ();    protected override ControlCollection  CreateControlsInstance  ();  // overrides Control  protected override void  CreateHandle  ();  // overrides Control  protected override void  DefWndProc  (ref Message  m  );  // overrides Control  protected override void  Dispose  (bool  disposing  );  // overrides ContainerControl  protected virtual void  OnActivated  (EventArgs  e  );    protected virtual void  OnClosed  (EventArgs  e  );    protected virtual void  OnClosing  (System.ComponentModel.CancelEventArgs  e  );    protected override void  OnCreateControl  ();  // overrides ContainerControl  protected virtual void  OnDeactivate  (EventArgs  e  );    protected override void  OnFontChanged  (EventArgs  e  );  // overrides Control  protected override void  OnHandleCreated  (EventArgs  e  );  // overrides Control  protected override void  OnHandleDestroyed  (EventArgs  e  );  // overrides Control  protected virtual void  OnInputLanguageChanged  (InputLanguageChangedEventArgs  e  );    protected virtual void  OnInputLanguageChanging  (InputLanguageChangingEventArgs  e  );    protected virtual void  OnLoad  (EventArgs  e  );    protected virtual void  OnMaximizedBoundsChanged  (EventArgs  e  );    protected virtual void  OnMaximumSizeChanged  (EventArgs  e  );    protected virtual void  OnMdiChildActivate  (EventArgs  e  );    protected virtual void  OnMenuComplete  (EventArgs  e  );    protected virtual void  OnMenuStart  (EventArgs  e  );    protected virtual void  OnMinimumSizeChanged  (EventArgs  e  );    protected override void  OnPaint  (PaintEventArgs  e  );  // overrides Control  protected override void  OnResize  (EventArgs  e  );  // overrides Control  protected override void  OnStyleChanged  (EventArgs  e  );  // overrides Control  protected override void  OnTextChanged  (EventArgs  e  );  // overrides Control  protected override void  OnVisibleChanged  (EventArgs  e  );  // overrides ScrollableControl  protected override bool  ProcessCmdKey  (ref Message  msg  , Keys  keyData  );  // overrides Control  protected override bool  ProcessDialogKey  (Keys  keyData  );  // overrides ContainerControl  protected override bool  ProcessKeyPreview  (ref Message  m  );  // overrides Control  protected override bool  ProcessTabKey  (bool  forward  );  // overrides ContainerControl  protected override void  ScaleCore  (float  x  , float  y  );  // overrides ScrollableControl  protected override void  Select  (bool  directed  , bool  forward  );  // overrides ContainerControl  protected override void  SetBoundsCore  (int  x  , int  y  , int  width  , int  height  , BoundsSpecified  specified  );  // overrides Control  protected override void  SetClientSizeCore  (int  x  , int  y  );  // overrides Control  protected override void  SetVisibleCore  (bool  value  );  // overrides Control  protected override void  UpdateDefaultButton  ();  // overrides ContainerControl  protected override void  WndProc  (ref Message  m  );  // overrides ContainerControl   // Events  public event EventHandler  Activated  ;    public event EventHandler  Closed  ;    public event CancelEventHandler  Closing  ;    public event EventHandler  Deactivate  ;    public event InputLanguageChangedEventHandler  InputLanguageChanged  ;    public event InputLanguageChangingEventHandler  InputLanguageChanging  ;    public event EventHandler  Load  ;    public event EventHandler  MaximizedBoundsChanged  ;    public event EventHandler  MaximumSizeChanged  ;    public event EventHandler  MdiChildActivate  ;    public event EventHandler  MenuComplete  ;    public event EventHandler  MenuStart  ;    public event EventHandler  MinimumSizeChanged  ; } 

Hierarchy

System.Object System.MarshalByRefObject System.ComponentModel.Component(System.ComponentModel.IComponen, System.IDisposable) Control(IOleContro, IOleObject , IOleInPlaceObject , IOleInPlaceActiveObject , IOleWindow , IViewObject , IViewObject2 , IPersist , IPersistStreamInit , IPersistPropertyBag , IPersistStorage , IQuickActivate , System.ComponentModel.ISynchronizeInvoke , IWin32Window) ScrollableControl ContainerControl(IContainerControl) Form

Subclasses

PrintPreviewDialog , ThreadExceptionDialog , System.Windows.Forms.Design.ComponentEditorForm

Returned By

ApplicationContext.MainForm , ContainerControl.ParentForm , Control.FindForm() , MainMenu.GetForm() , MdiClient.MdiChildren

Passed To

Application.Run() , ApplicationContext.{ApplicationContext() , MainForm} , System.Windows.Forms.Design.IUIService.ShowDialog() , System.Windows.Forms.Design.IWindowsFormsEditorService.ShowDialog() , ControlCollection.ControlCollection()



. Net Windows Forms in a Nutshell
.NET Windows Forms in a Nutshell
ISBN: 0596003382
EAN: 2147483647
Year: 2002
Pages: 794

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net