Style

Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio


Jump to: navigation, search
Exam Prep. Guides
70-505 Study Guide
70-526 Study Guide

1. Forms Controls

2. Integrating Data
3. Printing/Reporting
4. Enhancing Usability
5. Asynchronous Prog.
6. Forms Controls
7. Configure/Deploy

edit
Exam 70-526 Preparation Guide: Configure a Windows Form to control style.


Contents


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.


If you look in the Category view for the form, the following properties are listed under Style:


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.

Image:526-17.jpg


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.

Image:526-18.jpg


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.

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).

Image:526-19.jpg


IsMdiContainer

This property changes the display and behaviour of the form to an MDI parent form. The default value is set to false. 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.

Image:Np05.jpg

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");

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.

Image:526-20.jpg

For more information go to Create and configure a MenuStrip


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.

Image:526-21.jpg


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.

Image:526-22.jpg


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 take 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%.

Image:526_04.jpg


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 color 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.

Image:526-23.jpg


If ShowIcon is false when the primary form is shown, a generic icon will be displayed in the taskbar button for the application.

Image:526-24.jpg


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 inthe 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.
Image:526-25.jpg


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.

Image:526-26.jpg


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


Previous_Page_.gif Next_Page_.gif
© 2007-2008 Mike Kitchen



Personal tools