Visual Studio and Custom Control colors

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • kevin  cline

    Visual Studio and Custom Control colors

    I have code like this:

    public class MyControl: Control
    {
    public MyControl()
    {
    this.BackColor = MyStandardBackC olor;
    }

    public bool ShouldSerialize BackColor()
    {
    return BackColor != MyStandardBackC olor;
    }

    public void ResetBackColor( )
    {
    BackColor = MyStandardBackC olor;
    }
    }

    However, I have found that the VS2005 designer sets the control
    backcolor to the Microsoft gray after MyControl is constructed. Is
    there a way to prevent this from happening, so that my developers do
    not have to go and manually reset the BackColor property of every
    control?

    Is there anyone at Microsoft who might be interested in this problem.
    My bug reports are never acknowledged.

  • Rocky

    #2
    Re: Visual Studio and Custom Control colors

    Don't set it in the constructor.

    "kevin cline" <kevin.cline@gm ail.com> wrote in message
    news:1137106330 .683909.197620@ o13g2000cwo.goo glegroups.com.. .[color=blue]
    >I have code like this:
    >
    > public class MyControl: Control
    > {
    > public MyControl()
    > {
    > this.BackColor = MyStandardBackC olor;
    > }
    >
    > public bool ShouldSerialize BackColor()
    > {
    > return BackColor != MyStandardBackC olor;
    > }
    >
    > public void ResetBackColor( )
    > {
    > BackColor = MyStandardBackC olor;
    > }
    > }
    >
    > However, I have found that the VS2005 designer sets the control
    > backcolor to the Microsoft gray after MyControl is constructed. Is
    > there a way to prevent this from happening, so that my developers do
    > not have to go and manually reset the BackColor property of every
    > control?
    >
    > Is there anyone at Microsoft who might be interested in this problem.
    > My bug reports are never acknowledged.
    >[/color]


    Comment

    • kevin  cline

      #3
      Re: Visual Studio and Custom Control colors

      Did you have an alternative in mind?

      Comment

      • Rocky

        #4
        Re: Visual Studio and Custom Control colors

        You need to override the BackColor Property and apply the DefaultValue
        attribute. In the constructor set the this.BackColor = MyStandardBackC olor.
        Forget what I said about not setting the color in the constructor, my bad.


        "kevin cline" <kevin.cline@gm ail.com> wrote in message
        news:1137120356 .164721.123910@ g44g2000cwa.goo glegroups.com.. .[color=blue]
        > Did you have an alternative in mind?
        >[/color]


        Comment

        • kevin  cline

          #5
          Re: Visual Studio and Custom Control colors


          Rocky wrote:[color=blue]
          > You need to override the BackColor Property and apply the DefaultValue
          > attribute. In the constructor set the this.BackColor = MyStandardBackC olor.
          > Forget what I said about not setting the color in the constructor, my bad.[/color]

          There is no way to apply the DefaultValue attribute, because the
          default back color is computed from a configuration file.

          Comment

          Working...