views:

250

answers:

2

Anyone knows any tutorials with this topic?

I searched the net but I see mostly asp.net controls, not winforms.

+2  A: 

You might get more results if you search for 'UserControl' as you'll likely want to derive your custom/composite controls from that.

Typically, I'll place several controls on a UserControl, and expose only the methods and properties I need for the programmer to use it. A good example of such a control I made was a digital clock, where each digit was itself a custom control (which was actually a picturebox, coupled with some controlling logic). Then, I was able to drag n drop this control wherever I needed it.

Here's one tutorial you might find handy.

As an aside, when I did my google search, I used the following:

c# UserControl tutorial -asp

which ignored a lot of the ASP tutorials you were mentioning. It does seem that ASP programmers use a lot of these user controls!

Charlie Salts
Thanks Charlie, it's a good idea to exclude those. Would you also know why a groupbox used in a composite control also hide other controls that are part of the original composite control when you resize it? I know it hides included controls that are inside the groupbox, but is there a way to exclude these?
Joan Venge
Are you sure its *hiding* them and not covering them up? I've had the situation where I use a panel or groupbox inside another control, and resizing causes issues as I've set my anchors or docking incorrectly. Besides that, I'm not sure what's going on in your case.
Charlie Salts
Yeah it's covering them up. Resizing causes this issue where other parts of the composite control is covered up, like the group box controls every other control. I want this behaviour for later added controls but not part of the composite control. Also I turned off anchoring and it's still covering everything in the composite control.
Joan Venge
Docking may be an issue too - make sure it's set to 'None'. One technique I used once was to give each control a different color. That way, I could see which control was which as I resized, scrolled, etc. It's perfect for when you want to double check that all the controls are where they should be. When you're certain things are as they should be, set all the control colors back they way you want.
Charlie Salts
Thanks makes sense. I looked at it and they are set to None. Do you know what makes a groupbox encapsulate controls that are inside it? What kind of code defines it?
Joan Venge
If you look inside the designer-code, you'll see something like`panel.Controls.Add(instanceOfcontrol)` where `instanceOfControl` is a control *belonging* to your panel or groupbox. It's always possible that a control *inside* your panel is out of view. Think of moving a window offscreen - same principle.
Charlie Salts
I see, but I have a button in the center of a groupbox as a composite control. When I rescale it say half way, the button is also "hidden"/covered halfway. If I scale the composite control itself, then fine, but when I do this in the designer the groupbox behaves like this. I will see if I can find anything on this.
Joan Venge
+2  A: 

Try the WinForm Custom Controls section on CodeProject for many source code samples.

This one looks pretty 'how-to' oriented:
Write Your Own Bar Chart Winforms User Control

Jay Riggs