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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:35:33+00:00 2026-05-29T04:35:33+00:00

I’ve got a Compact Framework (3.5) control and I’d like it have a default

  • 0

I’ve got a Compact Framework (3.5) control and I’d like it have a default color of SystemColors.Window, similar in apprearance to an edit control. The problem I’m having is Visual Studio (2008) always renders that control on the design surface with a default BackColor of Control. I assume it is either pulling it from the default back color of the base Control, from the parent, or from the Site.

Anyone have any idea how to specify or otherwise inform Visual Studio what the default BackColor should be?

public class MoneyInput : Control
{

    public MoneyInput()
    {            
        base.BackColor = SystemColors.Window;
        base.ForeColor = SystemColors.WindowText;
    }

    public override Color BackColor
    {
        get
        {
            return base.BackColor;
        }
        set
        {
            base.BackColor = value;
            Repaint();                
        }
    }

}

And here is the appropriate section of my DesignTimeAttributes.xmta file. Note that I don’t really want the default color to White as you see below, I was just trying to get anything to work:

<DesktopCompatible>true</DesktopCompatible>

<Property Name="BackColor">

  <Browsable>true</Browsable>

  <DesignerSerializationVisibility>
    DesignerSerializationVisibility.Visible
  </DesignerSerializationVisibility>

  <DefaultValue>
    <Type>System.Drawing.Color</Type>
    <Value>System.Drawing.Color.White</Value>
  </DefaultValue>

  <Category>Appearance</Category>

  <Description>The background color of the control</Description>

</Property>

Just to add some more progress (or lack thereof), I added a log to the control so that I can see what is going on when I drop the control on the design surface. The write to the BackColor in the constructor does take effect and changes the color from Control to Window. But then something in the designer infrastructure sets the color (via the property) back to Control. This happens after the ctor but before the OnResize and OnHandleCreated. Now if the control serialized the BackColor property into the designer with the correct value then it would be safely set back, but the designer doesn’t contain default values.

One last edit, I think the default value syntax for specifiying an enum (as opposed to a base type) is not correct. I am using the solution I posted below, but it is a hack and hopefully the next person that comes along can solve it for real.

  • 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-29T04:35:34+00:00Added an answer on May 29, 2026 at 4:35 am

    I’m hoping to get a real answer still, but I’ll put down here my work-around solution:

    public class MoneyInput : Control 
    {
    
      // workaround for colors
      private bool _constructed = false;
      private int _handlesCreated; 
    
    
      public MoneyInput()
      {
          this.BackColor = SystemColors.Window;
          this.ForeColor = SystemColors.WindowText;
          _constructed = true;
      }
    
      public override Color BackColor
      {
          get
          {
              return base.BackColor;
          }
          set
          {
              // The logic below is based on:
              //
              // 1.  If not _constructed then we are getting called 
              //      from our ctor and we want the set to happen.
              // 2.  If we do not have a Handle yet then we are 
              //        getting called by the infrastructure that
              //        creates a control.  
              // 3.  At design-time, the VS designer applies the
              //        Ambient color even if we explicitly set 
              //        our own color.  It is supposed to only apply
              //        the Ambient if we have not explictly set
              //        a color.
              // 4.  At runtime we must accept any color changes
              //        that are passed to us.
    
    
              // see if VS designer is screwing with us
              bool ignoreColorSet =
                  _constructed
                  && _handlesCreated == 0
                  && RunningInDesigner;
    
    
              if (!ignoreColorSet)
              {
                  base.BackColor = value;
                  Repaint();
              }
    
    
          }
      }
    
    
      protected override void OnHandleCreated(EventArgs e)
      {
          _handlesCreated++;
          base.OnHandleCreated(e);         
      }
    
      private bool RunningInDesigner
      {
          get
          {
              // this control is mobile-only so if we are running on full
              //  windows we must be in design mode.  Note that this works
              //  even if we are not Sited yet, where as checking the 
              //  DesignMode property can't be done untl the control has
              //  a Site.
              return (System.Environment.OSVersion.Platform == PlatformID.Win32NT
                  || System.Environment.OSVersion.Platform == PlatformID.Win32Windows);
          }
      }
    
    }     
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have some data like this: 1 2 3 4 5 9 2 6
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I would like to count the length of a string with PHP. The string
I have a French site that I want to parse, but am running into

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.