65.9K
CodeProject is changing. Read more.
Home

Adding New Properties to a Windows

starIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIconemptyStarIcon

1.02/5 (17 votes)

Jun 17, 2006

1 min read

viewsIcon

34692

downloadIcon

343

Adding New Properties to a Windows

check just Form4 , Form5 in this sourse file

Sample Image - AddNewPropToWinForm.jpg

Introduction

Adding New Properties to a Windows Form

  1. In the Solution Explorer rightclick the project name and select Add, Add Windows Form from the context menu. Name the new form FormName
  2. 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: 

  1. //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;
    }
    }
    }
  2. ATTRIBUTES THAT CONTROL THE BEHAVIOR OF A PROPERTY

    Sample screenshot

 

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

Sample screenshot

Sample screenshot

 

  1. In the Solution Explorer rightclick
  2. the project name and select Add, Add Inherited
  3. Form from the context menu. Name the new form
  4. anyname  make it inherted form the previous form
  5. check the prperty window ...  the custom category & the Formstate new property