Adding New Properties to a Windows






1.02/5 (17 votes)
Jun 17, 2006
1 min read

34692

343
Adding New Properties to a Windows
check just Form4 , Form5 in this sourse file
Introduction
Adding New Properties to a Windows Form
-
In the Solution Explorer rightclick the project name and select Add, Add Windows Form from the context menu. Name the new form FormName
-
Right-click anywhere on the form and select View Code from the context menu. In the view, insert the following code just after the Windows Form Designer Generated Code region:
//define constant values for State public enum State{Idle, Connecting, Processing} //use this field as storage location //for FormState property private State formState; //set attributes for FormState property [Browsable(true), EditorBrowsable(EditorBrowsableState.Never), Description(“Sets the custom Form state”), Category(“Custom”)] //Creating FormState property public State FormState { get { return formState; } set { formState = value; switch (formState) { case State.Idle: this.BackColor = Color.Red; this.Text = “Idle”; break; case State.Connecting: this.BackColor = Color.Orange; this.Text = “Connecting...”; break; case State.Processing: this.BackColor = Color.Green; this.Text = “Processing”; break; } } }
ATTRIBUTES THAT CONTROL THE BEHAVIOR OF A PROPERTY
-
Browsable Indicates whether the property is displayed in the Properties window. Its default value is true.
EditorBrowsable Indicates whether the property should appear in the
IntelliSense list of an object in the code view. Its value is of
the EditorBrowsableState enumeration type, with three
possible values—Advanced, Always, and Never. Its default
value is Always, which means “always list this property.” If
you change the value to Never, the property is hidden from
the IntelliSense feature.
Description Specifies a description string for the property. When the
Description property is specified, it is displayed in the
description area of the Properties window when the property
is selected.
Category Specifies the category of the property. The category is used in
the Properties window to categorize the property list.
-
In the Solution Explorer rightclick
-
the project name and select Add, Add Inherited
-
Form from the context menu. Name the new form