如何结合物业类 [英] How to combine property class

查看:55
本文介绍了如何结合物业类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个窗口窗体应用程序,窗体上有一个PropertyGrid和3个按钮,场景如下:

1.当按下button1时,PropertyGrid将包含test1类.
2.按下button2时,PropertyGrid将包含test2类.
3.按下button3时,PropertyGrid将包含test1/test2类.
4. test1类具有例如3个属性字段.
5. test2类具有例如3个属性字段.

通常,按button1或button2以使用以下行来包含属性类是可以的:

I write a window form application, there are a PropertyGrid and 3 buttons on the form, the scenario is below :

1. when press button1, the PropertyGrid will include test1 class.
2. when press button2, the PropertyGrid will include test2 class.
3. when press button3, the PropertyGrid will include test1/test2 class.
4. the test1 class has, for example, 3 property fields.
5. the test2 class has, for example, anohter 3 property fields.

In general, press button1 or button2 to use the following lines to include property class is ok :

Test1 TheTest1 = New Test1();
PropertyGrid1.SelectedObject = TheTest1;


Test2 TheTest2 = New Test2();
PropertyGrid1.SelectedObject = TheTest2;



现在的问题是:

当我按下button3时,如何将Test1和Test2类组合在一起,以便PropertyGrid可以包含Test1和Test2类以具有所有这6个属性字段?
换句话说,我不会生成一个Test3属性类,它当然可以具有所有这6个属性字段,因为如果在任何时候我都将为所有类添加新的常规项目,那么每次我都必须更新该属性类的所有属性类时, Test1/Test2/Test3,似乎效率低下.

如果我的问题已解决,则只能更新Test1和Test2类,而不必更新Test3类.如果将使用许多属性类,这将更加有用.



The question now is that :

When I press button3, how can I combine Test1 and Test2 class together, so that PropertyGrid can include Test1 and Test2 class to have all those 6 property fields ?

In other words, I would not generate a Test3 property class, which of course may have all those 6 property fields, since if at any time I would add new general item for all classes, then each time I have to update all property classes of Test1/Test2/Test3, it seems be inefficient.

If my questin is solved, then I can only update Test1 and Test2 class, and need not update Test3 class. This will be more helpful, if there are many property classes will be used.

推荐答案

否,Propertygrid上只有一个对象.
创建一个同时包含Test1和Test2并公开所有属性的类.

干杯
No, only one object on a propertygrid.
Create a class that contains both Test1 and Test2 and exposes all properties.

Cheers


这篇关于如何结合物业类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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