小组控制 [英] group controls

查看:97
本文介绍了小组控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用struct和/或Dictionary对控件(图片框和标签)进行分组吗?分组控件将使我能够在用户控件中同时具有可移动控件吗?如何在C#中使用struct?帮帮我...:)

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... :)

推荐答案

1)是,2)否,3)阅读基本的C#手册.

结构"struct"与控件分组无关.尽管有许多基本区别(值,不是引用类型,除了封装/可见性,与OOP无关),这与类的封装方式几乎相同.字典是用于...等等等等的特殊类.如果结构的元素是整数,双精度数和字符串,则您不认为它们会做您可以形容为同时"的事情.为什么对控件这么奇怪的幻想?

相反,将您的控件作为子控件放到其他控件作为面板上,您便可以完成.移动父面板;控件将随之移动.



回答后续问题如何"?

我们应该使用Panel还是GropBox?让我们假设面板.设计时间:选择一个面板,在工具箱中,选择一个子控件的类型,在所选面板上单击鼠标-子控件的实例成为该面板的子控件.我建议使用嵌套面板,并使用Padding停放所有内容.

代码:
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.



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:
Panel parent = new Panel();

//assuming panel already set up by this moment

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

//...


这篇关于小组控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆