简体   繁体   English

以图形方式模拟.NET winforms应用程序

[英]Graphically template a .NET winforms application

I created a pretty fancy winforms app for my company. 我为我的公司创建了一个非常漂亮的winforms应用程序。 We had a graphic designer create the GUI, which was a pain to implement, all graphical buttons, lots of layered backgrounds and logos, animations, etc. 我们有一个图形设计师创建GUI,这很难实现,所有图形按钮,大量分层背景和徽标,动画等。

But now my company wants to resell it under different brands. 但现在我的公司想要在不同的品牌下转售它。 But since I mostly coded it well, I told my higher ups I could have a totally rebranded version done in under a week. 但由于我大部分时间编写得很好,我告诉我的更高层次,我可以在一周内完成一个完全重新命名的版本。 Basically all I would do is change a bunch of settings in an xml settings file, swap out the graphics with a new set, and build. 基本上我要做的就是更改xml设置文件中的一堆设置,用新的设置替换图形,然后构建。

Problem is if they want 5 or 6 different brands, I'd have 5 different builds to support (I really should be supporting 1, with diff templates) 问题是如果他们想要5个或6个不同的品牌,我将有5个不同的版本来支持(我真的应该支持1,使用diff模板)

The problem is its not easy (as far as I know) to swap out the images in a winforms app. 问题是在winforms应用程序中交换图像并不容易(据我所知)。 I have all the graphical resources in a single folder, but once each file is entered into its respective image list or container in visual studio, the only way to get it to update is to remove it and re-add it, changing the source folder doesnt cause the embedded image to refresh. 我将所有图形资源放在一个文件夹中,但是一旦将每个文件输入到visual studio中的相应图像列表或容器中,获取它的唯一方法是删除它并重新添加它,更改源文件夹不会导致嵌入的图像刷新。 This would be incredibly tedious for each build, there has got to be an easier way. 对于每个构建来说,这将是非常繁琐的,必须有一个更简单的方法。

Add On: 添加在:
So after some further investigation, I am leaning torwards some sort of resx file editor. 因此经过一些进一步的调查,我倾向于某种resx文件编辑器。 However the ones I have seen so far are more focused on translating strings to various languages, and are either very weak, or can not at all edit binary resources like bitmaps/png's. 然而,到目前为止,我所看到的更侧重于将字符串转换为各种语言,并且要么非常弱,要么根本无法编辑二进制资源,如bitmaps / png。 Though if you open a resx file in an xml viewer (I use notepad 2 with .resx set to use xml sytax highlighting) MS is kind enough to tell you exactly how each type is compiled (mostly variations of base 64) 虽然如果你在xml查看器中打开resx文件(我使用带有.resx的记事本2设置为使用xml sytax突出显示),MS很友好地告诉你每种类型的编译方式(主要是base 64的变体)

I think your goal should be having "brandable" resource files; 我认为你的目标应该是拥有“可品牌”的资源文件; you're essentially localizing your application, except you just have a few different versions of English. 你基本上是在本地化你的应用程序,除了你只有几个不同版本的英语。

You can use ResGen.exe and ResourceManager to load an external resources file, so you could use 5 different "resources" files but keep your code base the same. 您可以使用ResGen.exe和ResourceManager加载外部资源文件,因此您可以使用5个不同的“资源”文件,但保持您的代码库相同。

This post may also help... http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/b388c700-0e07-452b-a19e-ce02775f78a6/ 这篇文章也可以帮助... http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/b388c700-0e07-452b-a19e-ce02775f78a6/

Edit: BTW, I will second the comment that if you're going through a great deal of effort on this, consider WPF... Most of those "graphical" elements could possibly be done natively especially if it's gradients and stuff, not to mention the easy templating. 编辑:顺便说一下,我会在评论中说,如果你正在经历这方面的大量努力,请考虑WPF ......大多数“图形”元素可能是原生的,特别是如果它是渐变和东西,而不是提到简单的模板。

What I would do is just load all the graphics of the disk at start up from a folder and create any imagelists needed as appropriate, instead of doing this in the designer. 我要做的只是在文件夹启动时加载磁盘的所有图形,并根据需要创建所需的任何图像列表,而不是在设计器中执行此操作。 If you are worried that someone would steal the graphics, then I would create a simple file format (possibly encrypted) for my graphics and a small simple app for you or the designer to use to convert into this format from regular files. 如果你担心有人会窃取图形,那么我会为我的图形创建一个简单的文件格式(可能是加密的)和一个简单的小应用程序供你或设计师用来从常规文件转换成这种格式。 Then it's just a question of swapping out this folder between different brands. 那么这只是在不同品牌之间交换这个文件夹的问题。

If most of your forms are similar (ie same logo, same buttons on the bottom, etc.) you can use visual inheritance on WinForms to define a set of "Base Forms" from which your actual forms inherit. 如果您的大多数表单相似(即相同的徽标,底部相同的按钮等),您可以使用WinForms上的可视继承来定义一组“基本表单”,您的实际表单将从该表单继承。

If you develop a set of "Base Forms" for each of your brands, each set in a separate assembly you can plug-in the needed work to generate a new brand is reduced to generate a new set of Base Forms. 如果您为每个品牌开发一套“基本表单”,每个集合在一个单独的程序集中,您可以插入生成新品牌所需的工作,以生成一组新的基本表单。

Hope it helps 希望能帮助到你

It's too late now, but WPF would have been a better choice than WinForms, as it is easier to skin. 现在已经太晚了,但WPF本来是比WinForms更好的选择,因为它更容易皮肤。

However have a look at what DevExpress does for WinForms, as their controls have a skinning system. 但是看看DevExpress为WinForms做了什么,因为它们的控件有一个蒙皮系统。 It is not too hard to swap a DevExpress winform control for a standard winform control. 将DevExpress winform控件替换为标准winform控件并不太难。

I think you should be thinking about creating user controls for the dynamically replaceable areas of the form. 我认为您应该考虑为表单的动态可替换区域创建用户控件。 At runtime, you could swap out one assembly out for another. 在运行时,您可以将一个程序集换出另一个程序集。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM