Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / December 2004

Tip: Looking for answers? Try searching our database.

UserControl and containing controls problem...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Alon - 20 Oct 2004 09:39 GMT
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,
Jeff Gaines - 20 Oct 2004 10:44 GMT
> Hi,
> I'm making my own control which holds some buttons ant textboxes and
[quoted text clipped - 6 lines]
>
> 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?

Signature

Jeff Gaines Damerham Hampshire UK

Joey Callisay - 20 Oct 2004 12:22 GMT
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.

> Hi,
> I'm making my own control which holds some buttons ant textboxes and also
[quoted text clipped - 6 lines]
>
> 10X,
Alon - 20 Oct 2004 13:25 GMT
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 Callisay - 21 Oct 2004 02:19 GMT
> 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...
Alon - 21 Oct 2004 19:59 GMT
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,
Mick Doherty - 21 Oct 2004 20:36 GMT
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
//////

Signature

Mick Doherty
http://dotnetrix.co.uk/nothing.html

> hi,
> 10X for the "CanParent" tip, i solved it through overriding the
[quoted text clipped - 28 lines]
>
> 10X,
dd_smith - 28 Dec 2004 05:37 GMT
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.

> > Joey - it sounds rather complicated. and im not sure it's possible
> (although
[quoted text clipped - 17 lines]
> You should attach a custom designer to your custom panel control inheriting
> from ParentControlDesigner and then override the CanParent method...

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.