70-526 MCTS
Style
Several elements that contribute to the overall style of a form can be changed so that the form may
look a certain way without writing any code.
ControlBox
The default value is set to true. When you set this value to false, the
caption bar removes all elements other than the title.
To change the ControlBox property at run time, simply set the property to the desired
value.
this.ControlBox = false;
HelpButton
The default value is set to False. You set this value to true to display
a Help button in the form's caption bar. The value of the HelpButton property is ignored
if the Maximize or Minimize buttons are shown. So therefore, you must set
MaximizeBox and MinimizeBox to false.
To change the HelpButton property at run time, simply set the property to the desired
value.
this.HelpButton = true;
You can create an event handler for the HelpRequested event of the Control
class to display Help information to the user when the Help button of the form is clicked.
Control.HelpRequested Event (MSDN)
To demonstrate this further, this sample application (written in
C# Express) demonstrates usage of the help button. This code is ported from the
HelpRequested Event page.
Icon
A form's icon designates the picture that represents the form in the taskbar as well as the icon that is
displayed for the control box of the form. The default icon is used if no other icon is supplied. This
property has no effect if FormBorderStyle is set to FixedDialog because the form
will not display an icon. The following image shows an icon in the title panel (the control box).
To change the Icon property at run time, set the property to a new instance of the
Icon class:
this.Icon = new System.Drawing.Icon("shuttle.ico");
IsMdiContainer
The default value is set to False. This property changes the display and behaviour
of the form to an MDI parent form. When this property is set to true, the form displays
a sunken client area with a raised border. All MDI child forms assigned to the parent form are
displayed within its client area. To see this in action, take a look at the Simple Notepad application.
To change the IsMdiContainer property at run time, simply set the property to the desired
value.
this.IsMdiContainer = true;
MainMenuStrip
This property allows either a MenuStrip or a MainMenu to be associated with
the form. The following image shows a form with a MenuStrip having several menu items.
MaximizeBox
The default value is set to true. This property allows the Maximize button
to be enabled or disabled. A Maximize button enables users to enlarge a window to full-screen
size. To display a Maximize button, you must also set the form's FormBorderStyle
property to FormBorderStyle.FixedSingle, FormBorderStyle.Sizable,
FormBorderStyle.Fixed3D, or FormBorderStyle.FixedDialog.
A Maximize button automatically becomes a restore button when a window is maximized.
Minimizing or restoring a window automatically changes the restore button back to a Maximize
button.
Maximizing a form at run time generates a Resize event.
To change the MaximizeBox property at run time, simply set the property to the desired
value.
this.MaximizeBox = false;
MinimizeBox
The default value is set to true. This property allows the Minimize button
to be enabled or disabled. A Minimize button enables users to minimize a window to an icon.
To display a Minimize button, you must also set the form's FormBorderStyle
property to FormBorderStyle.FixedSingle, FormBorderStyle.Sizable,
FormBorderStyle.Fixed3D, or FormBorderStyle.FixedDialog.
Minimizing a form at run time generates a Resize event.
To change the MinimizeBox property at run time, simply set the property to the desired
value.
this.MinimizeBox = false;
Opacity
The default value is set to 100%. The opacity of the Form can be changed by
setting the Opacity property of the form. The property takes a percentage of opaqueness
from zero (makes the form completely invisible) to 100 (completely solid). The sample shown here has
the Opacity of the form set to 50%.
This property is not supported when RightToLeftLayout is set to true.
The Opacity property differs from the transparency provided by the
TransparencyKey property, which only makes a form and its controls completely transparent
if they are the same colour as the value specified in the TransparencyKey property.
To change the Opacity property at run time, simply set the property to the desired value.
Note that this value is a decimal between zero and one.
this.Opacity = .50;
ShowIcon
The default value is set to true. This property contains a Boolean value that indicates
whether the form's Icon is displayed in the caption bar of the form.
If ShowIcon is false when the primary form is shown, a generic icon will
be displayed in the taskbar button for the application.
This property has no effect if FormBorderStyle is set to FixedDialog.
To change the ShowIcon property at run time, simply set the property to the desired value.
this.ShowIcon = false;
ShowInTaskbar
The default value is set to true. This property indicates whether the form is displayed
in the Windows taskbar. You may want to set this property to false if the application is to
be shown in the task tray.
To change the ShowInTaskbar property at run time, simply set the property to the desired
value.
this.ShowInTaskbar = false;
SizeGripStyle
The default value is set to Auto. This property sets the style of the size grip to
display in the lower-right corner of the form. The values of the SizeGripStyle enumeration
are:
Auto - The sizing grip is automatically displayed when needed.
Hide - The sizing grip is hidden.
Show - The sizing grip is always shown on the form.
To change the SizeGripStyle property at run time, simply set the property to the desired
value.
this.SizeGripStyle = SizeGripStyle.Hide;
TopMost
The default value is set to false. This property indicates whether the form should be
displayed as a topmost form. A topmost form is a form that overlaps all the other (non-topmost) forms
even if it is not the active or foreground form. Topmost forms are always displayed at the highest point
in the z-order of the windows on the desktop.
To change the TopMost property at run time, simply set the property to the desired
value.
this.TopMost= true;
TransparencyKey
This property may be assigned a colour. All areas of the form that have the same
BackColor will be displayed transparently. This can be understood by a quick example.
- Create a new Windows application.
- Drop a
Button on the Form.
- Set the
TransparencyKey property to Control.
- Run the application.
As you move the form around your desk, you are able to see all of the icons or other applications that
are behind the application.
This property is not supported when RightToLeftLayout is true.
To change the TransparencyKey property at run time, simply set the property to the desired
value.
this.TransparencyKey = SystemColors.Control;
MSDN references
Form.ControlBox Property
Form.HelpButton Property
Form.Icon Property
Form.IsMdiContainer Property
Form.MainMenuStrip Property
Form.MaximizeBox Property
Form.MinimizeBox Property
Form.Opacity Property
Form.ShowIcon Property
Form.ShowInTaskbar Property
Form.SizeGripStyle Property
Form.TopMost Property
Form.TransparencyKey Property
© Publicjoe, 2007
|