Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old October 5th, 2007, 04:42 PM
Authorized User
 
Join Date: Mar 2004
Location: Mesa, AZ, USA.
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

  #2 (permalink)  
Old October 6th, 2007, 09:02 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
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 -/
  #3 (permalink)  
Old October 11th, 2007, 03:54 AM
Authorized User
 
Join Date: Mar 2004
Location: Mesa, AZ, USA.
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.

  #4 (permalink)  
Old October 11th, 2007, 05:35 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
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 -/
  #5 (permalink)  
Old October 11th, 2007, 05:45 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
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 -/
  #6 (permalink)  
Old October 12th, 2007, 09:03 PM
Authorized User
 
Join Date: Mar 2004
Location: Mesa, AZ, USA.
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.

 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 06:36 AM
Picture box container controls save to image mujeeb General .NET 0 May 20th, 2006 04: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



All times are GMT -4. The time now is 01:12 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.