Creating GroupBox with Radio Buttons from enum using reflection

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gugale at Lincoln

    Creating GroupBox with Radio Buttons from enum using reflection

    Hi,

    I am using reflection to read names from enum and creating radio buttons
    inside a groupbox. Everything is working fine. However, I am not able to
    adjust the size of the group box to fit the content. Is there a simple
    solution to this problem? Parent of group box is FlowLayoutPanel which fills
    the parent form.

    string[] names = Enum.GetNames(p i.PropertyType) ; //pi is a PropertyInfo
    object which represents a property of type enum.

    GroupBox gbx = new GroupBox();
    //gbx.AutoSize = true;
    gbx.Name = "gbx" + pi.Name;
    gbx.Text = pi.Name;
    gbx.Padding = new Padding(2, 5, 2, 2);
    panel.Controls. Add(gbx);

    TableLayoutPane l tlp = new TableLayoutPane l();
    tlp.ColumnCount = (int)Math.Floor (Math.Sqrt(name s.Length));
    tlp.Dock = DockStyle.Fill;
    tlp.Padding = new Padding(1);

    //int maxRBLength = 0;
    foreach (string name in names)
    {
    RadioButton rb = new RadioButton();
    rb.Name = "rb" + name;
    rb.Text = name;
    rb.AutoSize = true;
    rb.Margin = new Padding(0, 0, 0, 0);
    //if (rb.Width maxRBLength) maxRBLength = rb.Width;
    tlp.Controls.Ad d(rb);
    }

    gbx.Controls.Ad d(tlp);


    Thanks
    SG


  • Jack Jackson

    #2
    Re: Creating GroupBox with Radio Buttons from enum using reflection

    On Fri, 11 Apr 2008 17:55:06 GMT, "Gugale at Lincoln"
    <gugale.newsgro up@gmail.comwro te:
    >Hi,
    >
    >I am using reflection to read names from enum and creating radio buttons
    >inside a groupbox. Everything is working fine. However, I am not able to
    >adjust the size of the group box to fit the content. Is there a simple
    >solution to this problem? Parent of group box is FlowLayoutPanel which fills
    >the parent form.
    >
    string[] names = Enum.GetNames(p i.PropertyType) ; //pi is a PropertyInfo
    >object which represents a property of type enum.
    >
    GroupBox gbx = new GroupBox();
    //gbx.AutoSize = true;
    gbx.Name = "gbx" + pi.Name;
    gbx.Text = pi.Name;
    gbx.Padding = new Padding(2, 5, 2, 2);
    panel.Controls. Add(gbx);
    >
    TableLayoutPane l tlp = new TableLayoutPane l();
    tlp.ColumnCount = (int)Math.Floor (Math.Sqrt(name s.Length));
    tlp.Dock = DockStyle.Fill;
    tlp.Padding = new Padding(1);
    >
    //int maxRBLength = 0;
    foreach (string name in names)
    {
    RadioButton rb = new RadioButton();
    rb.Name = "rb" + name;
    rb.Text = name;
    rb.AutoSize = true;
    rb.Margin = new Padding(0, 0, 0, 0);
    //if (rb.Width maxRBLength) maxRBLength = rb.Width;
    tlp.Controls.Ad d(rb);
    }
    >
    gbx.Controls.Ad d(tlp);
    >
    >
    >Thanks
    >SG
    >
    It doesn't work if groubbox.AutoSi ze = True? If the groupbox is too
    large make sure AutoSizeMode is set to GrowAndShrink.

    Comment

    • Peter Duniho

      #3
      Re: Creating GroupBox with Radio Buttons from enum using reflection

      On Fri, 11 Apr 2008 10:55:06 -0700, Gugale at Lincoln
      <gugale.newsgro up@gmail.comwro te:
      Hi,
      >
      I am using reflection to read names from enum and creating radio buttons
      inside a groupbox. Everything is working fine. However, I am not able to
      adjust the size of the group box to fit the content.
      You need to set the AutoSize property of all of your relevant containers
      -- GroupBox, TableLayoutPane l, and possibly the FlowLayoutPanel and the
      containing Form as well -- to "true". Once you've done that, it should
      work fine.

      The GroupBox won't know to resize unless the TableLayoutPane l also
      resizes. If your form is large enough always, then the GroupBox's parents
      should be fine, but if not, they need to also be set to resize by setting
      their AutoSize property to "true".

      Pete

      Comment

      • Gugale at Lincoln

        #4
        Re: Creating GroupBox with Radio Buttons from enum using reflection

        No it doesn't. It just shrinks to a dot. I think it is because I am using
        TableLayoutPane l inside the group box. But I have no other options.


        "Jack Jackson" <jjackson@cinno vations.netwrot e in message
        news:bp9vv31q4e cr71vi1sq8tjjl2 fpa1paptl@4ax.c om...
        On Fri, 11 Apr 2008 17:55:06 GMT, "Gugale at Lincoln"
        <gugale.newsgro up@gmail.comwro te:
        >
        >>Hi,
        >>
        >>I am using reflection to read names from enum and creating radio buttons
        >>inside a groupbox. Everything is working fine. However, I am not able to
        >>adjust the size of the group box to fit the content. Is there a simple
        >>solution to this problem? Parent of group box is FlowLayoutPanel which
        >>fills
        >>the parent form.
        >>
        > string[] names = Enum.GetNames(p i.PropertyType) ; //pi is a
        >PropertyInfo
        >>object which represents a property of type enum.
        >>
        > GroupBox gbx = new GroupBox();
        > //gbx.AutoSize = true;
        > gbx.Name = "gbx" + pi.Name;
        > gbx.Text = pi.Name;
        > gbx.Padding = new Padding(2, 5, 2, 2);
        > panel.Controls. Add(gbx);
        >>
        > TableLayoutPane l tlp = new TableLayoutPane l();
        > tlp.ColumnCount = (int)Math.Floor (Math.Sqrt(name s.Length));
        > tlp.Dock = DockStyle.Fill;
        > tlp.Padding = new Padding(1);
        >>
        > //int maxRBLength = 0;
        > foreach (string name in names)
        > {
        > RadioButton rb = new RadioButton();
        > rb.Name = "rb" + name;
        > rb.Text = name;
        > rb.AutoSize = true;
        > rb.Margin = new Padding(0, 0, 0, 0);
        > //if (rb.Width maxRBLength) maxRBLength = rb.Width;
        > tlp.Controls.Ad d(rb);
        > }
        >>
        > gbx.Controls.Ad d(tlp);
        >>
        >>
        >>Thanks
        >>SG
        >>
        >
        It doesn't work if groubbox.AutoSi ze = True? If the groupbox is too
        large make sure AutoSizeMode is set to GrowAndShrink.

        Comment

        • Gugale at Lincoln

          #5
          Re: Creating GroupBox with Radio Buttons from enum using reflection

          It worked. Thanks!

          "Peter Duniho" <NpOeStPeAdM@nn owslpianmk.comw rote in message
          news:op.t9glkem b8jd0ej@petes-computer.local. ..
          On Fri, 11 Apr 2008 10:55:06 -0700, Gugale at Lincoln
          <gugale.newsgro up@gmail.comwro te:
          >
          >Hi,
          >>
          >I am using reflection to read names from enum and creating radio buttons
          >inside a groupbox. Everything is working fine. However, I am not able to
          >adjust the size of the group box to fit the content.
          >
          You need to set the AutoSize property of all of your relevant
          ontainers -- GroupBox, TableLayoutPane l, and possibly the FlowLayoutPanel
          and the containing Form as well -- to "true". Once you've done that, it
          should work fine.
          >
          The GroupBox won't know to resize unless the TableLayoutPane l also
          resizes. If your form is large enough always, then the GroupBox's parents
          should be fine, but if not, they need to also be set to resize by setting
          their AutoSize property to "true".
          >
          Pete

          Comment

          Working...