UserControl and containing controls problem...

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I'm making my own control which holds some buttons ant textboxes and also
has a panel control.
in design time i want to drop another controls into the panel that is in my
usercontrol.

the problem is that the added controls are added to the usercontrol and not
to the panel...

10X,
 
Hi,
I'm making my own control which holds some buttons ant textboxes and
also has a panel control.
in design time i want to drop another controls into the panel that is
in my usercontrol.

the problem is that the added controls are added to the usercontrol
and not to the panel...

10X,

Alon

I asked a similar question some time ago and from the response it seems
this is not possible, you can't use drag and drop to add other controls
to a user control at design time.

I'm surprised that you have achieved the success you have, are you sure
the control you are adding is being added to your user control? Does it
move around when you move the user control or is it left behind?
 
You can expose the Panel on the hosted container (form) where the
UserControl is also created. If it is also a component being designed, you
can just drag controls into it and the said controls will be added in its
(Panel's) Controls Collection. The only trick is how and when to create the
panel component using the IDesignerHost.CreateComponent method so it will be
designable and then add it to the Controls collection of the UserControl. I
believe one can do this on the Initialize method of the control's designer
class when a control is dragged onto the form and the designer is being
initialized for the dragged control/component.
 
Jeff - yes. when i relocate my usercontrol (at runtime or design) the
controls i added to it are attached .
Joey - it sounds rather complicated. and im not sure it's possible (although
i didnt try)
as a solution i can always do it all as a component which inherit a panel
and so on... i think it should work but needs a lot more background work
without inheriting the usercontrol...

it's pity the usercontrol is so poor, rather nice potential.

by the way, does anyone knows the design attributes that can help me decides
which controls the user can add on design time to a container (ie panel) and
which he cant ?


thanks.
 
Joey - it sounds rather complicated. and im not sure it's possible (although
i didnt try)
as a solution i can always do it all as a component which inherit a panel
and so on... i think it should work but needs a lot more background work
without inheriting the usercontrol...

I was able to replicate the .NET TabControl with buttons to click on and
panels as detail where user can drag controls into. Btw: WinForm controls
including panel is already a component. The idea is to create the control
from IDesignerHost so it is present on the container surface at design time.
http://www.divil.co.uk/net/articles/designers/collectioncontrols.asp
by the way, does anyone knows the design attributes that can help me decides
which controls the user can add on design time to a container (ie panel) and
which he cant ?

You should attach a custom designer to your custom panel control inheriting
from ParentControlDesigner and then override the CanParent method...
 
hi,
10X for the "CanParent" tip, i solved it through overriding the
"OnControlAdded" method. which is better way to do it ?

and regarding my base problem, i kind of got to the next phase - i now have
a usercontrol of type "A" who can hold lots of usercontrols of type "B". if
i drag the "A" and then drag the "B" into "A" i CAN add other controls to
"B". that was my initial meaning !!!
BUT, while this situation is ok, i rather want "A" to have a collection
property of "B"s (like tabcontrol with tabpages etc) with all "B"'s
properties.
this cause me 2 problems:
1) i understood i need a collection class and an item class and lots of
other stuff. is there a good article/code example anywhere about it ? couldnt
find any that is really thorough... (Joey - i already saw the article you
attached, 10X a lot but this example do not really take care all the aspects
i need, although when read it, i started to understand what is waiting for
me....:))
2) i kind of succeeded in doing something like a collection (simple property
who makes on design time "B" and add it to "A") but then i couldnt see it on
the "InitializeComponent" methode of the main form, in other words - i
couldnt add to "B" other controls...
i figure that if problem 1 will be solved i wont be bothered by 2 but if
there's something to do on the meantime... :)

10X,
 
add a reference to system.Design.dll

\\\\\\
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Drawing.Design

Public Class MyTabControl
Inherits UserControl

'Windows Form Designer generated code

<Editor(GetType(TabPageCollectionEditor), GetType(UITypeEditor))> _
Public ReadOnly Property TabPages() As ControlCollection
Get
Return Controls
End Get
End Property


Friend Class TabPageCollectionEditor
Inherits CollectionEditor

Public Sub New(ByVal type As System.Type)
MyBase.new(type)
End Sub

Protected Overrides Function CreateCollectionItemType() As System.Type
Return GetType(MyTabPage)
End Function

End Class


End Class

Public Class MyTabPage
Inherits ScrollableControl

'...

End class
//////
 
I have a similar user control designer issue. You mentioned ' I was able to
replicate the .NET TabControl with buttons to click on and panels as detail
where user can drag controls into.' Is there any way you can post that? I
am trying to develop a custom tab control that unfortunately extending the
existing tab control won't do.
 
Back
Top