Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 538401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:01:40+00:00 2026-05-13T10:01:40+00:00

While trying to write a custom control I’ve come across a problem with the

  • 0

While trying to write a custom control I’ve come across a problem with the System.Windows.Forms.TextFormatFlags enum in combination with the Visual Studio (2005/2008) editor. The reason for this problem seems to come from the fact that this enum has multiple members which map to a zero value. Selecting any of these members (GlyphOverhangPadding, Left, Default, Top) results in the editor setting the property to

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

The code compiles, as expected. However, selecting any non-zero member (e.g. “Right”) from the editor’s property grid results in the following:

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

Obviously this does not compile. Selecting more than one non-zero member (Through a UITypeEditor, e.g. “Right | Bottom”) 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 of the four zero-value members to any selected item.

If you wish to reproduce this issue:

  • Create a new project in Visual Studio 2005/2008 (Windows Forms Application)
  • Add a Custom Control to the project.
  • Add a private field and public property to the new class:

    private TextFormatFlags tff = TextFormatFlags.Default;

    public TextFormatFlags TFFProperty
    {
    get { return this.tff; }
    set { this.tff = value; }
    }

  • Compile the code

  • Open Form1 in the designer and add CustomControl1 to it
  • The code compiles fine
  • Now open the properties of CustomControl1 in the editor’s PropertyGrid
  • You should see the TFFProperty under the “Misc” section
  • The property offers several values, most of which contain a comma.
  • Selecting any of the values with a comma (e.g. “Left, Default, Top, HorizontalCenter) results in non compilable code

The same happens if you create your own enum with the Flags attribute and add more than one member mapped to zero (which is a kind of malformed flags enum?). I’ve verified that this is not a bug with the UITypeEditor I’m using (The same problem occurs without using the UITypeEditor). I’ve tried to circumvent the problem with a Converter, so far without success. If anyone has any ideas on how to solve this problem I’d be glad to hear them.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T10:01:40+00:00Added an answer on May 13, 2026 at 10:01 am

    I checked through the various classes in the System.ComponentModel.Design.Serialization namespace using Reflector, and I think the CodeDom serializer is being a bit naughty.

    Enums get handled by EnumCodeDomSerializer.Serialize, whose purpose is to take an enum and turn it into a System.CodeDom.CodeExpression object that represents what you see in the designer file.

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

    I think Enum.ToString is the ultimate cause of what you’re seeing:

    If multiple enumeration members have the same underlying value and you attempt to retrieve the string representation of an enumeration member’s name based on its underlying value, your code should not make any assumptions about which name the method will return.

    Admittedly the MSDN page on Enum.ToString doesn’t talk about the commas, but it still doesn’t seem safe to rely on the output of Enum.ToString being a valid C# expression.

    I’m not sure what this means for your control:

    • Clearly you can define your own replacement for TextFormatFlags and do it without the duplicated zero flags
    • You may be able to hack it with a custom type converter, maybe one that converts to InstanceDescriptor. This gives you a little more control over what appears in the designer-generated code.
    • You could possibly expose an int to the designer serializer but a TextFormatFlags to the property grid

    Edit: The comma-separated list behaviour of Enum.ToString is in fact documented

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 287k
  • Answers 287k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer EDIT: Okay, I think you just want: var sites =… May 13, 2026 at 5:06 pm
  • Editorial Team
    Editorial Team added an answer Set the KeyPreview property on the Form to True: http://msdn.microsoft.com/en-us/library/system.windows.forms.form.keypreview.aspx May 13, 2026 at 5:06 pm
  • Editorial Team
    Editorial Team added an answer Is there any pros to use HTML 5 doctype even… May 13, 2026 at 5:06 pm

Related Questions

I am writing a method that's intended to return a dictionary filled with configuration
How can I bind the default Window background color of the theme to a
Does anybody know of a way to customize the appearance of the string based
I'm trying to write an ASP.NET MVC application where user privilege is based upon
I am trying to find a good way to tail a file on a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.