UserControls as containers?


G

Guest

I'm trying to write what I thought would be a pretty simple user control but I'm not having much luck. Basically, I want a groupbox with an associated checkbox, so that when the checkbox is false the groupbox is disabled.

I've been able to create the control (as a UserControl) and I've included th
[System.ComponentModel.Designer(typeof(System.Windows.Forms.Design.ParentControlDesigner))
attribute, but I'm still not getting the behavior that I want

When I drop a button on this control in the designer all I see is the area outline (not the button as is usual) and I don't see the button at all at runtime

I suspect that "somehow" I need to intercept the adding of the button to my usercontrol and redirect it to the groupbox within my usercontrol (or at least this seems like the thing to do), but I can't see how to do this. Overriding various methods and interfaces has left me scratching my head. I imagine this is pretty easy, it's just a matter of know how it's done

In short I basically want to create a usercontrol that contains a groupbox and I want embedded groupbox to act just like it does on a form.

Can anyone point me in the right direction or to an online sample that tackles this issue

Thanks
Static
 
Ad

Advertisements

L

Lloyd Sheen

Ok, just did it with no supporting code. Just drag and drop.

Steps are:

1. Create a windows app (or one you want to use).
2. Add a new project (Windows Control)
3. Open the windows control designer, drop a groupbox on it , change the
dock to Fill
4. Build the solution. Note nothing done yet in windows app.
5. Open toolbox (assuming no errors in build)
6. Check the tab My User Controls and your control should be there.
7. Open a form in the windows app, drag the UC to the form.
8. Now drag another control like a button into the UC area. It should
now show correctly and you can add the code to the UC for whatever
processing you want to override.

Lloyd Sheen

static@community.nospam said:
I'm trying to write what I thought would be a pretty simple user control
but I'm not having much luck. Basically, I want a groupbox with an
associated checkbox, so that when the checkbox is false the groupbox is
disabled.
I've been able to create the control (as a UserControl) and I've included the[System.ComponentModel.Designer(typeof(System.Windows.Forms.Design.ParentCon
trolDesigner))]
attribute, but I'm still not getting the behavior that I want.

When I drop a button on this control in the designer all I see is the area
outline (not the button as is usual) and I don't see the button at all at
runtime.
I suspect that "somehow" I need to intercept the adding of the button to
my usercontrol and redirect it to the groupbox within my usercontrol (or at
least this seems like the thing to do), but I can't see how to do this.
Overriding various methods and interfaces has left me scratching my head. I
imagine this is pretty easy, it's just a matter of know how it's done.
In short I basically want to create a usercontrol that contains a groupbox
and I want embedded groupbox to act just like it does on a form.
 
L

Lloyd Sheen

Sorry the above post was with old non working code. I have one that works
and will try to find it.

Lloyd

Lloyd Sheen said:
Ok, just did it with no supporting code. Just drag and drop.

Steps are:

1. Create a windows app (or one you want to use).
2. Add a new project (Windows Control)
3. Open the windows control designer, drop a groupbox on it , change the
dock to Fill
4. Build the solution. Note nothing done yet in windows app.
5. Open toolbox (assuming no errors in build)
6. Check the tab My User Controls and your control should be there.
7. Open a form in the windows app, drag the UC to the form.
8. Now drag another control like a button into the UC area. It should
now show correctly and you can add the code to the UC for whatever
processing you want to override.

Lloyd Sheen

static@community.nospam said:
I'm trying to write what I thought would be a pretty simple user control
but I'm not having much luck. Basically, I want a groupbox with an
associated checkbox, so that when the checkbox is false the groupbox is
disabled.
I've been able to create the control (as a UserControl) and I've
included
[System.ComponentModel.Designer(typeof(System.Windows.Forms.Design.ParentCon
trolDesigner))]
attribute, but I'm still not getting the behavior that I want.

When I drop a button on this control in the designer all I see is the
area
outline (not the button as is usual) and I don't see the button at all at
runtime.
I suspect that "somehow" I need to intercept the adding of the button to
my usercontrol and redirect it to the groupbox within my usercontrol (or at
least this seems like the thing to do), but I can't see how to do this.
Overriding various methods and interfaces has left me scratching my head. I
imagine this is pretty easy, it's just a matter of know how it's done.
In short I basically want to create a usercontrol that contains a
groupbox
and I want embedded groupbox to act just like it does on a form.
Can anyone point me in the right direction or to an online sample that tackles this issue ?

Thanks,
Static
 
Ad

Advertisements

G

Guest

I've made some very minor progress by overloading the OnControlAdded and OnControlRemoved methods. I don't think this is the right track, but I think it's close to it. I expected to be able to use OnControlAdded to change the parent of the added control to the embedded groupbox, but it didn't work. When I do this and I try to drop a button onto the control I get the very helpful message "'child' is not a child control of this parent". However, I can drop the button on the form and drag it to the control without error. When I do this the Adds do NOT get serialized in the InitializeComponent method of the form. I assume this is because I need a DesignerSerializationVisibility "somewhere", but it's not at all clear where. The more I work on this the less obvious I find the "container design"

I'm very surprised that no one other than MS has been able to make this sort of control work. I'm also rather disappointed that MS hasn't documented these classes better. The more I look thru the docs the more I find properties and methods with very brief descriptions and examples that are completely unrelated to the topic.

I still believe that there is some rather simple procedure for making this sort of thing work. However finding this simple path is beginning to seem quite hopeless.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top