Click here to Skip to main content
15,889,034 members
Articles / Programming Languages / C#
Article

Adding New Properties to a Windows

Rate me:
Please Sign up or sign in to vote.
1.02/5 (19 votes)
17 Jun 20061 min read 34.1K   342   10   2
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)<FONT face=MacUSADigital-Regular size=1>
    {
    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;
    }
    }
    </FONT>}</FONT></FONT></FONT></FONT><FONT face=AGaramond-Regular size=3><FONT face=MacUSADigital-Regular size=1><FONT face=MacUSADigital-Regular size=1>
  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

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer (Senior) Areny.Net
Egypt Egypt
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionHow to assign List property to control?? Pin
User-Rock25-Jul-07 23:09
User-Rock25-Jul-07 23:09 
Help please....

How can asssign List property to custom control in C#?

List is containing collection of myObject

List myObject where myObject is a class



GeneralPerfect Pin
Todd Wilder6-Aug-06 14:25
Todd Wilder6-Aug-06 14:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.