.net - Flags enumeration with multiple zero values problem (TextFormatFlags) -


While trying to write a custom control I've come across a problem with the system. In the Windows.Forms.TextFormatFlags enum combination, the reason for this problem with the Visual Studio (2005/2008) editor comes from the fact that there are several members of this enum, which map the zero value. To set any of these members (GlyphOverhangPadding, Left, Default, Top) in the editor

  this.customControl.TextFormatFlags = System.Windows.Forms.TextFormatFlags.GlyphOverhangPadding ;  

Code compiled, however, as expected, select any non-zero member (such as "right") in the following from the grid results of the editor's property:

  this.customControl.TextFormatFlags = System.Windows.Forms.TextFormatFlags.Left, Default, Top, Correct;  

Obviously it does not compile. Selecting more than one non-zero member (via UITypeEditor, such as "right | down") results in the following:

  this.customControl.TextFormatFlags = ((System.Windows.Forms .TextFormatFlags) ((System.Windows.Forms.TextFormatFlags.Left, Default, Top, Right | System.Windows.Forms.TextFormatFlags.Left, Default, Top, Bottom)));  

As you can see, the editor adds three out of four zero-value members to any selected item.

If you want to reproduce this problem:

  • Create a new project in Visual Studio 2005/2008 (Windows Forms Application)
  • Add custom controls in the project.
  • A personal add field and public property for the new category:

    Private text format flags tff = TextFormatFlags.Default;

    Public Text Format Flag TFFProperty {get this return; } Set {this.tff = value;

  • Collect code
  • Designer Open Form 1 and add it to custom control1
  • Code compile
  • Now open the properties of Custom Control1 in the editor's propertygrid
  • You can create "Miscellaneous" Section should look at TFFProperty
  • Assets provide multiple values, mostly
  • selecting any value with commas (for example "Left, Default, Top, Horizontal Center ) Non-compatible code Result

The same if you create your own enum with the properties of the flag and add more than one mapped number of mapped (which is a type of distorted flag) ?). I have verified that it is using the UIPP editor to get the same problem without using UITPeter. I have tried to solve the problem with a converter, so far without success, if anyone Near this If there is any idea about solving the problem, then I would be happy to hear it.

I < Using Code> System.ComponentModel.Design.Serialization Reflector tested through various classes in the namespace and I think the codedom serializer is getting a little naughty.

Enums are controlled by EnumCodeDomSerializer.Serialize , whose purpose is to take an enum and convert it to a System.CodeDom.CodeExpression object You see in the designer file.

Expression | This method correctly uses the CodeBinaryOperatorExpression to handle the aspect. However, for individual enum values, it uses Enum.ToString via EnumTypeConverter and the resulting string sticks directly into the expression tree.

I think the ultimate cause of what you are seeing:

If multiple counting members have the same underlying value and you have a calculator based on your basic value If you try to get the representation of the name of the member's name, then your code

assumes that talk about MSDN page comma on Enum.ToString Does not, but it still does not have Enum.ToString a valid C # expression Trust is not safe to rely on production.

I'm not sure what it means for your control:

  • Obviously you define your code for TextFormatFlags You can do this without a duplicated zipper flag.
  • You may be able to hack it with a custom type converter, it may be a instancedescriptor Change it to the things you see in the designer-generated code It gives more control.
  • You may display int with designer serial but TextFormatFlags on the property grid

< Strong> Edit:


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

jquery - SimpleModal Confirm fails to submit form -