一般的Windows表单模板 [英] Generic Windows Form Template

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

问题描述

我创建一个接受T和使用自定义反射属性来创建在运行时标签和输入控件通用的Windows窗体

I am creating a generic Windows Form that accepts T and uses reflection with custom attributes to create labels and input controls at run-time.

例如:

class GenericForm<T>: Form where T : ICloneable<T>  
{  
}  

下面是上一个问题的链接表单代码:太问题

Here's a link to a previous question for the form code: SO Question.

这形式可以接受下面的实体类为例:

This form could accept the following entity class as an example:

class Vehicle: ICloneable<Vehicle>  
{  
    public int Id { get; set; }  
    public int Name { get; set; }  
    public int Description { get; set; }  
}  



正如你能想象,在形式背后的魔法会使用反射来确定数据类型,验证标准,首选的控制类型的使用,等等。

As you could imagine, the magic behind the form would use reflection to determine data types, validation criteria, preferred control types to use, etc.

而不是重新发明轮子,我认为这将是值得一问的,所以如果有人知道的这样的框架。不用说,我在寻找一些简单的,而不是笨重的框架。

Rather than re-inventing the wheel, I thought it would be worth asking on SO if anyone knows of such frameworks. Needless to say, I'm looking for something simple rather than a bulky framework.

推荐答案

据我所知,有没有框架,在运行时生成UI代码。有很多之前做到这一点的工具(代码生成器)。但是,你不会有仅更改代码的好处 - 你有一个额外的步骤,你将需要启动代码生成

As far as I know, there are no frameworks that generate the UI code at runtime. There are plenty of tools (code-generators) that do this before. But you wouldn't have the advantage of "only" changing the code - you'd had an extra step where you would need to start the code generator.

如果您真要在运行时创建UI信息 - 我为您的性能属性,会告诉你的UI产生怎样处理这个属性(如果没有属性给出 - 为您的数据类型默认)。这是一个很大的编码,但可以为小型节省您的时间,以在未来的媒体项目。

If you really want to create the UI information at runtime - I'd generate Attributes for your properties, that would tell your UI generator how to deal with this property (if no Attribute is given - have a default for your datatypes). It's a lot of coding but could save you time for small to medium projects in the future.

您可以做的另一件事是外部的UI信息到一个XML文件,并有一个发电机。实际上,有一个框架,这是否 - 看看框架再运动。我不知道如果UI的部分是免费的,但它有一些功能(即混入),可以帮助你完成你的任务。

Another thing you could do is to externalize your UI information into an XML file and have a generator for that one. There's actually a framework that does that - have a look at the re-motion framework. I don't know if the part of the UI is free but it has some functionality (i.e. mixins) that could help you fulfilling your task.

这篇关于一般的Windows表单模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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