Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Windows Forms
  4. Override Text property in GroupBox

Override Text property in GroupBox

Scheduled Pinned Locked Moved Windows Forms
csharpvisual-studioquestion
9 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dybs
    wrote on last edited by
    #1

    Greetings, I have a control that inherits from GroupBox and contains some other default controls and behavior. I am trying to override the GroupBox Text property so the text appears in a label in the GroupBox, and have the GroupBox text itself be an empty string. However, when I set the Text property in the designer, both my label and the GroupBox show the same text. What am I missing? I am using C# 2.0 using VS 2005 (I haven't upgraded to VS 2008 because I need at least the Standard edition for building my installers, and upgrading to VS 2008 Standard or Pro is not in the budget at the moment).

    public class ExpandableGroupBox : GroupBox
    {
    public ExpandableGroupBox()
    {
    base.Text = "";
    }
    public override Text
    {
    get
    {
    return label.Text;
    }
    set
    {
    label.Text = value;
    }
    }
    }

    Thanks, Dybs

    G H 2 Replies Last reply
    0
    • D dybs

      Greetings, I have a control that inherits from GroupBox and contains some other default controls and behavior. I am trying to override the GroupBox Text property so the text appears in a label in the GroupBox, and have the GroupBox text itself be an empty string. However, when I set the Text property in the designer, both my label and the GroupBox show the same text. What am I missing? I am using C# 2.0 using VS 2005 (I haven't upgraded to VS 2008 because I need at least the Standard edition for building my installers, and upgrading to VS 2008 Standard or Pro is not in the budget at the moment).

      public class ExpandableGroupBox : GroupBox
      {
      public ExpandableGroupBox()
      {
      base.Text = "";
      }
      public override Text
      {
      get
      {
      return label.Text;
      }
      set
      {
      label.Text = value;
      }
      }
      }

      Thanks, Dybs

      G Offline
      G Offline
      geali_dor
      wrote on last edited by
      #2

      Did you copy the source from your Visual Studio direct in here? If it's like that, you won't be able to compile the code anyway, because you are missing the type of your Text property

      public class ExpandableGroupBox : System.Windows.Forms.GroupBox
      {
          public ExpandableGroupBox()
          {
              base.Text = "";
          }
      
          public override **string** Text
          {
              get
              {
                  return label.Text;
              }
              set
              {
                  label.Text = value;
              }
          }
      }
      

      hack the planet

      D 1 Reply Last reply
      0
      • G geali_dor

        Did you copy the source from your Visual Studio direct in here? If it's like that, you won't be able to compile the code anyway, because you are missing the type of your Text property

        public class ExpandableGroupBox : System.Windows.Forms.GroupBox
        {
            public ExpandableGroupBox()
            {
                base.Text = "";
            }
        
            public override **string** Text
            {
                get
                {
                    return label.Text;
                }
                set
                {
                    label.Text = value;
                }
            }
        }
        

        hack the planet

        D Offline
        D Offline
        dybs
        wrote on last edited by
        #3

        No, I typed it from memory, and lack of sleep was setting in. I do have the type in the actual code and it compiles. (If it didn't compile, I couldn't really complain about both my label and the GroupBox showing the same text :) ). Dybs

        1 Reply Last reply
        0
        • D dybs

          Greetings, I have a control that inherits from GroupBox and contains some other default controls and behavior. I am trying to override the GroupBox Text property so the text appears in a label in the GroupBox, and have the GroupBox text itself be an empty string. However, when I set the Text property in the designer, both my label and the GroupBox show the same text. What am I missing? I am using C# 2.0 using VS 2005 (I haven't upgraded to VS 2008 because I need at least the Standard edition for building my installers, and upgrading to VS 2008 Standard or Pro is not in the budget at the moment).

          public class ExpandableGroupBox : GroupBox
          {
          public ExpandableGroupBox()
          {
          base.Text = "";
          }
          public override Text
          {
          get
          {
          return label.Text;
          }
          set
          {
          label.Text = value;
          }
          }
          }

          Thanks, Dybs

          H Offline
          H Offline
          Henry Minute
          wrote on last edited by
          #4

          I have no idea why your code is not working. I would probably tried something similar. However, take a look at this article[^] (it's got some pretty pictures). Is that the sort of thing that you want? If not, I found that by Googling c# override text of groupbox, there were lots of hits including UXTheme'd GroupBox control[^], from here on CP. I haven't read it but it might give you some ideas.

          Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

          D 1 Reply Last reply
          0
          • H Henry Minute

            I have no idea why your code is not working. I would probably tried something similar. However, take a look at this article[^] (it's got some pretty pictures). Is that the sort of thing that you want? If not, I found that by Googling c# override text of groupbox, there were lots of hits including UXTheme'd GroupBox control[^], from here on CP. I haven't read it but it might give you some ideas.

            Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

            D Offline
            D Offline
            dybs
            wrote on last edited by
            #5

            Henry, Thanks for the links, but the article's aren't quite what I'm after. What I'm trying to make is a GroupBox that will expand/collapse when a header is clicked. In my case I'm using a ToolStrip at the top of the GroupBox, and I want the ToolStrip's label to show the Text property instead of the GroupBox. Rather than inherit from UserControl and do everything by hand, it seemed reasonable to inherit from GroupBox and just override the Text property, and add the expand/collapse behavior. I've almost got it working now. I tried using new instead of override for the Text property, and it gives me the desired effect, but the value I set in the designer doesn't show up when the application run. It only shows me the default value. It's the same situation described here[^]. The value is not being written to the InitializeComponent method for my form. I tried setting the DesignerSerializationVisibility attribute to Visible, but that didn't work. I've looked at the other attributes listed on MSDN[^], but I don't see any others that I know would help. Here's what my code looks like now:

            public partial class ExpandableGroupBox : GroupBox
            {
                public ExpandableGroupBox()
                {
                    InitializeComponent();
                    base.Text = "";
                }
            
                \[EditorBrowsable(EditorBrowsableState.Always), Browsable(true),
                DesignerSerializationVisibility(DesignerSerializationVisibility.Visible),
                Bindable(true)\] 
                public new string Text
                {
                    get
                    {
                        return toolStripLabel1.Text;
                    }
                    set
                    {
                        toolStripLabel1.Text = value;
                    }
                }
            }
            

            After some more searching, it looks like I may be able to use something like DevExpress's XtraNavBar[

            H 1 Reply Last reply
            0
            • D dybs

              Henry, Thanks for the links, but the article's aren't quite what I'm after. What I'm trying to make is a GroupBox that will expand/collapse when a header is clicked. In my case I'm using a ToolStrip at the top of the GroupBox, and I want the ToolStrip's label to show the Text property instead of the GroupBox. Rather than inherit from UserControl and do everything by hand, it seemed reasonable to inherit from GroupBox and just override the Text property, and add the expand/collapse behavior. I've almost got it working now. I tried using new instead of override for the Text property, and it gives me the desired effect, but the value I set in the designer doesn't show up when the application run. It only shows me the default value. It's the same situation described here[^]. The value is not being written to the InitializeComponent method for my form. I tried setting the DesignerSerializationVisibility attribute to Visible, but that didn't work. I've looked at the other attributes listed on MSDN[^], but I don't see any others that I know would help. Here's what my code looks like now:

              public partial class ExpandableGroupBox : GroupBox
              {
                  public ExpandableGroupBox()
                  {
                      InitializeComponent();
                      base.Text = "";
                  }
              
                  \[EditorBrowsable(EditorBrowsableState.Always), Browsable(true),
                  DesignerSerializationVisibility(DesignerSerializationVisibility.Visible),
                  Bindable(true)\] 
                  public new string Text
                  {
                      get
                      {
                          return toolStripLabel1.Text;
                      }
                      set
                      {
                          toolStripLabel1.Text = value;
                      }
                  }
              }
              

              After some more searching, it looks like I may be able to use something like DevExpress's XtraNavBar[

              H Offline
              H Offline
              Henry Minute
              wrote on last edited by
              #6

              A while ago I wrote an article on Nested Controls (which is what the controls inside a GroupBox are) and their design time behavior. I don't know if you feel that it might have relevance to your situation, but have a look and see. Here is a link Designing Nested Controls[^]. Hope there is something useful in there for you. :)

              Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

              D 2 Replies Last reply
              0
              • H Henry Minute

                A while ago I wrote an article on Nested Controls (which is what the controls inside a GroupBox are) and their design time behavior. I don't know if you feel that it might have relevance to your situation, but have a look and see. Here is a link Designing Nested Controls[^]. Hope there is something useful in there for you. :)

                Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

                D Offline
                D Offline
                dybs
                wrote on last edited by
                #7

                Great article! I ran into this problem with a TableLayoutPanel awhile back (we made the panels all resizable at runtime) and we couldn't figure out how to drop controls into the different panels at design time. This is exactly what we need. Great set of resource links, too. I'll play around with the designer stuff tomorrow and see if I can bend it to my will. :-D Thanks, Dybs

                1 Reply Last reply
                0
                • H Henry Minute

                  A while ago I wrote an article on Nested Controls (which is what the controls inside a GroupBox are) and their design time behavior. I don't know if you feel that it might have relevance to your situation, but have a look and see. Here is a link Designing Nested Controls[^]. Hope there is something useful in there for you. :)

                  Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

                  D Offline
                  D Offline
                  dybs
                  wrote on last edited by
                  #8

                  I finally got it to work. I added the Category and DefaultValue attributes, in addition to the code above, and now it's working. Not sure why that would have affected it but hey, I'll take it. :) Thanks again. Dybs

                  H 1 Reply Last reply
                  0
                  • D dybs

                    I finally got it to work. I added the Category and DefaultValue attributes, in addition to the code above, and now it's working. Not sure why that would have affected it but hey, I'll take it. :) Thanks again. Dybs

                    H Offline
                    H Offline
                    Henry Minute
                    wrote on last edited by
                    #9

                    Good stuff!! :)

                    Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups