Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
|
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 5th, 2007, 03:42 PM
Authorized User
 
Join Date: Mar 2004
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default Container User Controls

Hello All,

I am having trouble finding some help on the internet, perhaps my search criteria is not specific enough.

Anyway, what I'm looking to do, is find out how to create a user control that is a container, kinda of like a master page in asp.net. Where I can design the control look, yet there is a part specified for content for a desktop app.

This is something that I want to build so that I can add controls to its container part on design time, not run time.

A good example of this, is the outlook bar. I could have a main container, perhaps a panel object. Then I would drag a few of my container type user controls in it, and for each of them, put whatever I was in design time in it.

I can do this in pure code at run-time, but I could see this being a lot easier and less tedious if I could find a way to visually just drag my control off the toolbox, then drag whatever normal .net control into the container part of my control.

I'm sorry if I dont make much sense, this is perhaps why I havent found my answer googling ;p

 
Old October 6th, 2007, 08:02 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

My search for "asp.net user container" gave me this link as the first hit: http://www.codeproject.com/aspnet/pa...econtainer.asp

I believe the hard part is not creating a user control that contains children control, but the design time interface.

/- Sam Judson : Wrox Technical Editor -/
 
Old October 11th, 2007, 02:54 AM
Authorized User
 
Join Date: Mar 2004
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Skimming through that link, im not sure if that's what I'm looking for (although I only skimmed).

Just to be a little more descriptive, this is what I mean:
1.) I create a desktop app project.
2.) I create a user control, this control contains a label and a panel in it (panel background color white to identify where its at), the label is just there to show that the whole is a control, not necessary.
3.) I go back to the main form of the desktop app and drag over an instance of the user control.
4.) I grab a button or any other object really and drag it over to the panel of the user control.
5.) I move the user control some, but notice the button was not put inside the page of the user control, but acts as a child control of the main form.

So (in this example), what I really wanted was to have the button become a child control of the panel in the user control.

I can add this on runtime and add event handlers programmatically, but I would like the ease of just dragging the button into the panel (to be a child of it), and use the regular double-click to create event handler code, etc.

Thanks again for the reply, maybe I can look through the link you showed me and see if theres something I can extract from that.

 
Old October 11th, 2007, 04:35 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Didn't realise you meant Winforms.

I changed my google search and came up with this:

http://www.codeproject.com/vb/net/Cu...nerControl.asp

Again, no idea if this does what your after but I'd recommend downloading the sample code and having a look. I suspect that trying to get it to work in the designer is going to be very hard indeed.


/- Sam Judson : Wrox Technical Editor -/
 
Old October 11th, 2007, 04:45 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

After a bit more googling (which you could have been doing yourself btw) the key to your problem is adding the following attribute to your user control:

Code:
[Designer("System.Windows.Forms.Design.ParentControlDesigner,System.Design", typeof(System.ComponentModel.Design.IDesigner))]
public partial class UserControl1 : UserControl
{
... etc


/- Sam Judson : Wrox Technical Editor -/
 
Old October 12th, 2007, 08:03 PM
Authorized User
 
Join Date: Mar 2004
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Nice, thats getting close to what I wanted. I think I can work with this and figure out what I'm looking for. The only thing wrong with this, is that the control I want to add to the user control becomes a child of the user control instead of the panel (also goes behind the panel, just a z-index type issue I can figure out). I really appreciate your help on helping me on the path that I need to take.






Similar Threads
Thread Thread Starter Forum Replies Last Post
User controls' content: Chapter 2 User Controls AGS BOOK: Professional ASP.NET 2.0 Server Control and Component Development ISBN: 978-0-471-79350-2 10 July 26th, 2007 05:36 AM
Picture box container controls save to image mujeeb General .NET 0 May 20th, 2006 03:46 AM
User Controls Duncan Pro VB.NET 2002/2003 2 December 1st, 2003 05:41 AM
User Controls Duncan Pro VB.NET 2002/2003 1 October 27th, 2003 12:51 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.