如何在运行时更改完整的GUI [英] How do I change complete GUI on the runtime

查看:91
本文介绍了如何在运行时更改完整的GUI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

这是关于在运行时更改应用程序GUI的问题。



有两个窗体应用程序具有相同的控件,相同的程序代码和只有一个差异,控件的排列方式不同。 GUI是不同的。



如果检查程序代码,两个MainForm.Designer.cs类之间只有区别。



我感兴趣的是如何只使用一个应用程序,它将在运行时加载选定的MainForm.Designer.cs类,并使用它来更改应用程序GUI。



这样的事情可能吗?





一切顺利,
$ b $bŽeljkoPeric



我尝试了什么:



既然我不知道怎么做,我没有尝试过。

Hello,
This is question about changing application GUI during a runtime.

There are two windows form applications with same controls, same program code and only one difference, controls are arranged differently. GUI is different.

If program code is examined , there is only difference in between two MainForm.Designer.cs classes.

I am interested how to use only one application, that will load selected MainForm.Designer.cs class, on the runtime, and use it to change application GUI.

Is such thing possible ?


All the best,
Željko Peric

What I have tried:

Since that I do not know how, I have tried nothing.

推荐答案

启动表单是由program.cs中的一行创建的:

The "startup form" is created by a line in program.cs:
static class Program
    {
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
        {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new frmMain());  // <<-- This sets the startup app
        }
    }

因此,在那里更改Form并运行应用程序并不困难 - 这可能是在命令行开关上,或者其他什么。



另一种方法是实际更改您创建/执行的控件,这在技术上是可行的 - 它们是在Form.designer.cs文件中构建的,因此要选择set A或者设置B - 但这实际上是一个PITA,因为它会使这两个形式的未来发展变得非常复杂。



我这样做的方式比较简单:将每个Form转换为UserControl,并选择要在运行时显示哪个控件,使其填充表单区域。

So it wouldn't be difficult to just change the Form there and Run the app - that could be on a command line switch, or whatever.

The other approach is to actually change which controls you create / execute which is technically possible - they are built in your Form.designer.cs file so it wouldn't be difficult to get that to select "set A" or "set B" - but that's actually a PITA because it would make future development of the two "forms" seriously complicated.

The way I'd do it is simpler: convert each Form into a UserControl and select which control you want to display at run time, making it fill the form area.


除了OriginalGriff的优秀答案,我还想提一下剥皮。

虽然Winforms很难皮肤,但是你可以使用免费的 Krypton Toolkit GitHub - ComponentFactory / Krypton:用于.NET的Krypton WinForms组件 [< a href =https://github.com/ComponentFactory/Kryptontarget =_ blanktitle =New Window> ^ ]



有关简单的Winforms Skinning示例,请参阅: Ye Olde GroupBox的新皮肤 [ ^ ]



当然使用WPF时,还有更多的蒙皮可能性。
In addition to OriginalGriff's excellent answer, I would also like to mention skinning.
Although Winforms are notoriously difficult to skin, you can use the free Krypton Toolkit: GitHub - ComponentFactory/Krypton: Krypton WinForms components for .NET[^]

For a simple Winforms Skinning example see: A New Skin for Ye Olde GroupBox[^]

Of course when using WPF there are more possibilities for skinning.


这篇关于如何在运行时更改完整的GUI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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