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

  • Home
  • SEARCH
  • 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 7717651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:57:20+00:00 2026-06-01T02:57:20+00:00

I have a control, with a certain property that requires a somewhat heavy init

  • 0

I have a control, with a certain property that requires a somewhat heavy init routine be called every time the property is changed.

Of course, the public property isn’t required to be set initially, but the init routine must be called with a default value.

How can I structure this, so that the init routine is only called once, regardless of whether the designer set the property or not?

Currently, it is called once in the constructor, and then again when the property setter is called through designer code (if specified). What’s a good way of dealing with 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-06-01T02:57:21+00:00Added an answer on June 1, 2026 at 2:57 am

    If you place the DefaultValueAttribute in front of your property, specifying the actual default value of your property, the windows forms designer will not generate code that initializes the property

    [DefaultValue(0)]
    private int _myProperty;
    public int MyProperty { 
        get { return _value; }
        set
        {
            if (value !=  _myProperty) {
                 _myProperty = value;
                 HeavyInitialization();
            }
        }
    }
    

    Properties are only initialized in InitializeComponent(); if the value specified in the properties window differs from the specified default value.

    If you do not need to set this property in the properties window at all, then you can hide it from the properties window with the BrowsableAttribute. You can disable serialization (code generation for InitializeComponent) completely with the DesignerSerializationVisibilityAttribute.

    [Browsable(false)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
    public int MyProperty {
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have certain critical bash scripts that are invoked by code I don't control,
We have certain configuration files which we want to be in version control as
I have created a user control to handle adding comments to certain business entities,
I have an ASP.NET server control which relies on JQuery for certain functionality. I've
WPF controls have certain properties (UserControl.Resources, UserControl.CommandBindings) that can have items added to them
I have a custom control for a LayoutPanel that holds child controls. I want
Couldn't find an answer to this one. I have a WPF ListView control that
Let me explain my situation. I have made a user control that contains an
I'm convinced that certain images on my site are not caching properly. I have
I have a textBox that needs to be transformed into a DatePicker under certain

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.