Placing a User Control into a groupbox - c#

I have tried to search this question but most of the questions I've seen deal with how to place a user control into a group box in winforms. I have a slightly different question.
I have a form that contains a combo box and group box. I have a series of user controls that I want to swap in and out of the group box depending on the combo box selection. This all works perfectly fine.
The issue I am running into is that it seems to place the user control in the top left corner of the group box. This obscures the border and any text on the group box itself. I have tried changing the Padding in the group box and also the margins on the user control and nothing appears to change how the group box places the control.
I'm aware I can use a panel or manually place the controls after they are added, but I was hoping someone might know how the group box determines where to place controls and why it seems like padding/margins are being ignored.
Does padding only matter when the group box has multiple controls and the user control is being seen as a single control that doesn't need padded?

Set the UserControl's Dock property to Fill when inside the GroupBox.
The Dock property uses the DisplayRectangle property of the parent control, which will respect the interior border area the GroupBox uses for the text caption and border lines.

Related

How to extend ComboBox to allow an overlayed button

I need to create a combo box with an overlayed button like the one in the Toolbox panel of Visual Studio:
I created a control derived from System.Windows.Forms.UserControl with a PictureBox onto a System.Windows.Forms.ComboBox.
The problem is that when the text is too long, it starts scrolling after the PictureBox, going under it. I tried setting the MaxLength property of the ComboBox appropriately, but in this way the user would be limited in the number of characters he could enter because the text doesn't scroll.
What can I do to achieve the desired functionality?

Auto size items on form

I have a form with buttons, groupboxes etc. that looks like this:
The problem is that this form doesnt fit on some smaller resolutions. How can I make this form so that all its components would resize? I tried anchors and autosize preperties but I could only get it to work for picturebox.
What anchor and autosize settings did you use?
Long story short, use the anchor and dock properties.
See an example and explanation HERE.
I made a test example (for visuals), and you can see the anchor properties I used for an example group box that has a picture box below it. It scales left and right and up, but not downward (which would cover the picture box). You can then use similar border properties and settings to set the positions of the buttons and elements within the group box. See the group box properties image:
Group Box Properties Image

Hiding a panel should force controls below to move up and resize the form

OK, this is driving me a bit nuts at this point. Time to ask the crowd:
I have a form that consists of: two vertical "halves" created by a SplitContainer. Inside the bottom "half" / SplitContainer panel... I have:
A set of fields/controls for the user to fill out, contained within a panel.
Below that, a panel containing buttons for "submit", "cancel"...and one that's "show/hide". This "show/hide" is intended to show/hide the panel I just described in point 1 above.
What I want to happen is: when the user clicks to "hide" the panel of controls, not only do those controls vanish, but also:
The panel containing the submit, cancel and show/hide buttons moves up (so that we don't have this big blank space where the now-hidden panel once was).
The form resizes itself vertically so as to make up for the now-hidden panel and the fact that we've moved the bottom controls upwards.
I have no problem getting the panel of controls/fields to show/hide. But I can't seem to figure out how to accomplish the other two tasks. I've tried various combinations of AutoSize, AutoSizeMode, and Dock options.
Any suggestions?
If you put all your controls into a FlowLayoutPanel where the children are arranged vertically, then hiding some controls should cause the "lower" controls to move up the page.
You might still need to write some code to resize the form itself once the optional content has been hidden or before it's shown.

VS2010 Winforms DataGridView in Tabpage Loses Container Coordinates

The form is a complex construction with label and text controls at the top, a tab control at the bottom, and data grid views in some of the tab pages. I had just resized the fonts in most of the controls on the form from '8' (8.25) to '10' (9.75). Having saved it, when I reopen it numerous controls in the tab pages have either disappeared entirely or are improperly dimensioned, usually scrunched up in the upper left hand corner. Among the malformed controls are data grid views, multi-line text boxes, labels, and buttons. If I reposition and resize the forms, they are 'saved', but not to the dimensions I specify. Generally when this happens I find the entire form is beyond recovery.
Why does it happen, and what should I do to keep it from happening again?
Update:
I have another form with a similar arrangement: text boxes at the top for the 'main record', a tab collection at the bottom, and custom user controls embedded in two of the pages. Changing the font style on the tab control properties corrupted many of the controls in the subordinate pages. This was particularly true of the two custom user controls, both of which contain DataGridViews. However, some tab pages have nothing more than a multi-line text box, and these were also corrupted. I suspect that the controls that were corrupted were anchored on all four sides, certain text and label controls only anchored top-left weren't affected.
I locked the controls before applying the font style, locking does not change the outcome.

User Control dock inside Tab Page Windows Form

I have a TabControl. I add tab pages at runtime. On top of tabPage i add User Control at runtime.
Inside user Control i have richtextbox.
So its like TabControl-->TabPage--->UserControl-->RichTextBox & other controls.
I want my richtextbox to completely fill the space when i maximize. I tried Dock property and panel but no luck.
Any help is appreciated.
Thanks.
Not very clear what is your real problem, but just by guessing:
To me it seems that Dock.Fill can not fail in this condition. What can happen, IMHO, is that TabControl doesn't resize, so its children (richtextbox too) do not change their client area size.
In other words
Set Dock.Fill property on your RichText box
Check out TabControl's Dock, or Anchor properties.
Hope this helps.

Categories

Resources