【问题标题】:Is there a way in C# to create a design template for a component有没有办法在 C# 中为组件创建设计模板
【发布时间】:2014-04-15 00:46:05
【问题描述】:

在 C# 中有没有办法为组件创建设计模板(例如按钮) 项目中的所有按钮都将从模板继承设计。 每当我更改模板时,所有按钮都会继承更改。 我希望我的应用程序具有相同的外观 所有的按钮看起来都一样,所有的文本框...... 谢谢

【问题讨论】:

    标签: c# templates components modeling


    【解决方案1】:

    您想要做的可以通过创建您自己的控件继承类来实现。例如

    public class yourbuttontemplate : System.Windows.Forms.Button
    {
        yourbuttontemplate() //constructor
        {
            this.Height=20;
            this.Width=40;
            this.BackColor=Color.Blue;
        }
    }
    

    构建项目后,您的按钮应该在工具箱中可用,您可以使用此按钮代替默认的 Windows.Forms.Button。

    【讨论】:

    • 感谢您的回答。您的解决方案非常好,对我帮助很大。 (我以为只有用户控件出现在工具箱中)。我有一个观察结果:如果我通过工具箱添加控件,C# 设计器会自动覆盖控件的某些属性。因此,为了完成继承,用户应该在每次添加新控件时删除设计器覆盖的属性。
    猜你喜欢
    • 2021-09-27
    • 2022-11-28
    • 2021-04-17
    • 1970-01-01
    • 1970-01-01
    • 2013-02-16
    • 1970-01-01
    • 1970-01-01
    • 2019-11-10
    相关资源
    最近更新 更多