Click here to Skip to main content
15,912,837 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Can I group controls (picturebox and label) using struct and/or Dictionary? Will grouping controls will able me to have a simultaneous movable control in user control? How can I work with struct in c#? Help me... :)
Posted

1 solution

1) Yes, 2) No, 3) read elementary C# manual.

Structures "struct" have nothing to do with grouping of control. This is pretty much the same way of encapsulation as class, despite of many fundamental differences (value, not reference type, nothing related to OOP except encapsulation/visibility). And dictionary is a special class used for... blah-blah-blah. If element of structure are integers and doubles and strings, you don't think they will do something which you can characterize as "simultaneous". Why such a strange fantasy about controls?

Instead, put your controls as children onto some other control as panel and you'll be done. Move the parent panel; the controls will be moved with it.

[EDIT]

Answering a follow-up question "how"?

Shall we use Panel or GropBox? Let's assume Panel. Desing-time: select a panel, in toolbox, select a type of a child control, click mouse on selected panel -- an instance of child control becomes a child of the panel. I recommend using nested panels and dock everything using Padding.

Code:
C#
Panel parent = new Panel();

//assuming panel already set up by this moment

Label label = new Label();
label.Text = "&Blah-blah";
//...
parent.Children.Add(label);

//...
 
Share this answer
 
v3
Comments
yummy02 24-Jan-11 2:04am    
Thanks but how can I make a control as children into other control?
yummy02 24-Jan-11 3:49am    
I have a question, moving two different controls in a panel inside user control is possible. But let's say there's a 3 instances of picturebox and 3 corresponding instances of label below picturebox. Can I move picturebox and label below it simulataneously? I mean each pbox has a label partner. Can I move a pbox together with its partner without clicking label?
Sergey Alexandrovich Kryukov 24-Jan-11 9:53am    
Yes, when you move a parent, you move all children with it. Look, I never put any controls in a free positions at all. Everything is organized hierarchically. It's not possible to break alignment by accidental move.
yummy02 25-Jan-11 1:56am    
Thanks SAKryukov... :)
Espen Harlinn 6-Feb-11 14:51pm    
Good answer, a 5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900