Windows Develop Bookmark and Share   
 index > Windows Forms Designer > GroupBox in a UserControl, redux
 

GroupBox in a UserControl, redux

I'm trying to create a UserControl which contains a GroupBox, but I'm running into some designer issues. First, the repro steps:

1. Create a new Class Library project (in C#, VisualStudio 2005)

2. In UserControl1's designer, add a GroupBox

3. Set groupBox1's Dock property to Fill.

4. Build

5. Add a WinForm t the project

6. In Form1's designer, add a UserControl1 control

7. Try to add a Button (or any other control) to userControl11

I've searched on this issue already, and I did find a solution from Rong-Chun Zhang at http://forums.microsoft.com/MSDN/ShowPost.aspx?siteid=1&PostID=2439275, but the problem with this solution is that once the CheckableGroupBox control is added to the WinForm, it can't easily be resized or moved. To do so one needs to:

1. Change the selected item in the properties window from checkableGroupBox1.InternalGroupBx to checkableGroupBox1.

2. The you can resize or move because it is now the user control that has the focus.

If this control was something I was solely going to use by myself that would be fine (though cumbersome), however I plan to release this control to others and I don't like this because:

1. Unless you know this trick, it looks like the designer or the control is broken.

2. It's unintuitive to have to go to the properties window and select the CheckableGroupBox item.

I'm guessing what I need is a custom designer, however, I don't know very much about the Designer classes and haven't found very many articles/tutorial on the subject. (I have found some, though what I've seen isn't applicable to what I'm doing)

Any suggestions?

Thanks,

Jeff

Jeff99999  Thursday, September 25, 2008 5:52 PM

Hi, Jeff-- I've been researching the same problem, and Rong-Chun Zhang's solution appears to be the standard. I don't like it either, because it fully exposes the child control at design time, rather than simply enabling it to accept drops.

What I can tell you is that the custom Designer is a simple override of the base control designer that invokes EnableDesignMode(). There is really nothing to it. It is EnableDesignMode() that exposes the child control at design time.

I am playing around right now with capturing the user control DragDrop event in code and resetting the parent of any dropped control to the group box. I think that will give me the behavior I am looking for.

David Veeneman  Saturday, October 04, 2008 2:13 PM

You can use google to search for other answers

Custom Search

More Threads

• Difference between arrays and objects when referencing controls
• Forms inheritance properties problem
• Creating my own TabPage class
• Select a custom component in custom controls like DataSet/Datagrid
• Inherited forms
• Collection Editor only shows Object
• When and how should a custom control be used?
• Problem with my custom control crashing the Windows Forms Designer
• UserControl's child container's contents not being serialized
• designer errors: Object reference not set to an instance of an object