Windows Develop Bookmark and Share   
 index > Windows Forms General > Set component property value using Constants by Visual Studio IDE
 

Set component property value using Constants by Visual Studio IDE

Hi,

How canIset a component property value using a defined constant by IDE?

I write a Component that expose astring property. I would like to seta property value using a defined string constant by the Visual Studio IDE.

Here the example:

public class MyComponent : Component

{

private string myProperty;

public string MyProperty

{

set{ myProperty = value;}

get{ return myProperty;}

}

}

Then I put the Component into a Form and by IDE using the Property Windows I want to setthe value:MyProperty = MY_CONSTANT

Inside the Form's InitializeComponent() method authomatically it will be a line like this

this.myComponent.MyProperty = MY_CONSTANT;

P.s.: the defined constant is declared in a specific class.

public class MyConstants

{

public const string MY_CONSTANT = "Value";

}

Sorry for my broken english

Anonymous13919  Monday, May 19, 2008 1:06 PM

You cannot set this using the Designer, you would have to set it in the constructor, or somewhere else in the code of your form.

On a side note, I would discourage you from using public constants, as they are copied from assembly to assembly. Private constants are acceptable, but public constants might create some issues for you. In your current setup, using a public constant, you may as well simply enter the value of the constant in the IDE, as you'll achieve the same net result as using a public constant.

David M Morton  Monday, May 19, 2008 1:20 PM

You cannot set this using the Designer, you would have to set it in the constructor, or somewhere else in the code of your form.

On a side note, I would discourage you from using public constants, as they are copied from assembly to assembly. Private constants are acceptable, but public constants might create some issues for you. In your current setup, using a public constant, you may as well simply enter the value of the constant in the IDE, as you'll achieve the same net result as using a public constant.

David M Morton  Monday, May 19, 2008 1:20 PM

You can use google to search for other answers

Custom Search

More Threads

• Graphics Issue
• Why is a form inside a ContainerControl not painted as active form by .net framework?
• Winsock control
• checkListBox - savings values
• Items in ListView / ListBox change event does not exists
• How Managed User control runs in Internet Explorer
• vb6 form as owned by vb.net form
• Sorting & Searching a ListView in VirtualMode
• App.Config file along with an exe
• How to insert controls into header of DataGridView????