Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GroupBox won't show up

Status
Not open for further replies.

gib99

Programmer
Mar 23, 2012
51
CA
Hello,

I have a form with a UserControl inside it, and inside that UserControl is a GroupBox:

revision_form.jpg


Under certain conditions, I want to add another GroupBox below the first one. When those conditions are met, I add it dynamically as the following code snippet from the UserControl shows:

RevisionGroupBox.Dock = DockStyle.Top;

_newRevisionGroupBox = new GroupBox();
_newRevisionGroupBox.Text = "New Project Revision";
_newRevisionGroupBox.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
_newRevisionGroupBox.Dock = DockStyle.Bottom;
_newRevisionGroupBox.Size = new System.Drawing.Size(this.Width, 400);

Button ApplyButton = new Button();
ApplyButton.Text = "Apply";
ApplyButton.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
ApplyButton.DialogResult = DialogResult.OK;
_newRevisionGroupBox.Controls.Add(ApplyButton);

this.Controls.Add(_newRevisionGroupBox);

But the second GroupBox will not show up. It's supposed to show up in the grey area in the image above but that area remains grey.

I tried various things. For example, the first GroupBox's dock style is set to fill by default. When I add the second group box, I set the first groupbox to top and the second group box to bottom. I'm also giving the second groupbox a size as you can see. I'm also calling refresh on the UserControl.

Your help is very much appreciated.
 
What is "this"? Is it the form, panel or your usercontrol?

"this" should be the object hosting the new groupbox (ie its parent control)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top