Class constant reference in C # Designer?

I am stuck with the designer for this current project I am working on. One thing we usually do is set as many properties as possible for each control we add. We do this using the Properties designer window. This causes all of these customizations to be set / managed in the generated .designer.cs file instead of having to be maintained with our code.

There is one thing that I always wish to do, but I can never figure out how to do it, and that refers to constants from the properties window.

For example, in mine SpinEdit

I am working with, I would like to set the maximum value Decimal.MaxValue

, but if I just type it in the properties window, I get an error. How can I refer to this variable from the constructor properties window?

Here is an image of what I am trying to do, in case it becomes clearer:

Set property using constant

However trying these causes and errors as soon as I try to keep the focus of that textbox highlighted in the picture. But it works fine in code, the following line compiles just fine, so why can't I do it in designer ?:

alarmStationSpinEdit.Properties.MaxValue = Decimal.MaxValue;

      

EDIT . It looks like I need to make this question even more explicit. I am expecting one of two possible answers. They would be in the format:

1) Yes, it is possible. This is how you do it .....

or

2) No, this is impossible. That's why ..... (preferably with links, as I find it hard to believe).

+3


source to share


1 answer


1) Yes, it is possible if you are a component developer. The Visual Studio property grid lets you specify a custom value converter for a component property. This makes it possible to convert a string value entered into the property grid to a value read from a constant.

The TypeConverterAttribute is used to assign a custom type converter to a property. This is a detailed MSDN article with examples explaining what a type converter is and what it can be used for: Implement a type converter

2) No, this is not possible if you are using a third-party component, and this component does not support assigning constant values ​​to its properties.



By default, the Visual Studio property grid takes values ​​as is. If the property is of decimal type, you cannot assign a string to it.

The value you assign via the property grid will not evaluate as a C # or VB.NET expression. Visual Studio treats this as meaning.

+1


source







All Articles