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 964965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:55:06+00:00 2026-05-16T01:55:06+00:00

How does one tell the designer the default value of a Property when it

  • 0

How does one tell the designer the default value of a Property when it is not one of the types supported by DefaultValue()? For instance, a Padding, or a Font.

Normally, when you use a Windows Forms control, the default values will be in a normal font in the Properties window, and changed (non-default) values will be in bold. E.g.

Image of properties windows with non-default values in bold

In this sample, the default value of ShowAddress is false and the default value of ShowName is true. This effect is achieved with the following:

[DefaultValue(false)]
public bool ShowAddress {
  get { return mShowAddress; }
  set { 
    mShowAddress = value; 
    Invalidate();
  }
}

[DefaultValue(true)]
public bool ShowName { ... }

However, when I tried to do something for Padding, I failed miserably:

[DefaultValue(new Padding(2))]
public Padding LabelPadding { ... }

Which of course won’t compile.

How on Earth would I do this?

  • 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-16T01:55:06+00:00Added an answer on May 16, 2026 at 1:55 am

    Try this:

    private static Padding DefaultLabelPadding = new Padding(2);
    private internalLabelPadding = DefaultLabelPadding;
    public Padding LabelPadding { get { return internalLabelPadding; } set { internalLabelPadding = value; LayoutNow(); } }
    
    // next comes the magic
    bool ShouldSerializeLabelPadding() { return LabelPadding != DefaultLabelPadding; }
    

    The property browser looks for a function named ShouldSerializeXYZ for each property XYZ. Whenever ShouldSerializeXYZ returns false, it doesn’t write anything during code generation.

    EDIT: documentation:

    • [1]: http://msdn.microsoft.com/en-us/library/ms973818.aspx
    • [2]: http://msdn.microsoft.com/en-us/library/53b8022e.aspx
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How does one tell it where to put the AVD? by default it is
Can any one tell what does below given lines means? The lines below are
Can any one tell me? what does following means in ruby program: obj =
Please can some one briefly tell me with example what does the means of
Possible Duplicate: How does one tell if an IDisposable object reference is disposed? Is
Possible Duplicate: Oracle "(+)" Operator Can some one tell me what does (+) sign
I would like to know how can I tell what percent does one image's
How does one tell the XML parser to honor leading and trailing whitespace? Dim
does one perform better over the other in terms of indexing/quering etc ? e.g.
How does one wait until all of the Javascript is loaded before curling a

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.