扩展System.Windows.Forms.Button并更改c#中的默认文本
发布时间:2020-12-14 05:36:10 所属栏目:Windows 来源:网络整理
导读:我通过扩展System. Windows.Forms.Button类创建了一个自定义控件按钮. 我在新类的构造函数中设置了默认的.Text .Width和.Height. 当我将此控件放到表单上时,IDE足够聪明,可以注意构造函数中指定的宽度和高度,并将这些属性分配给正在创建的新按钮,但它会忽略T
我通过扩展System.
Windows.Forms.Button类创建了一个自定义控件按钮.
我在新类的构造函数中设置了默认的.Text .Width和.Height. 当我将此控件放到表单上时,IDE足够聪明,可以注意构造函数中指定的宽度和高度,并将这些属性分配给正在创建的新按钮,但它会忽略Text属性,并指定.Text按钮是“ucButtonConsumables1” 有没有办法将.Text设置为我选择的默认值? public partial class ucButtonConsumables : System.Windows.Forms.Button { public ucButtonConsumables() { this.Text = "Consumables"; this.Width = 184; this.Height = 23; this.Click += new EventHandler(ucButtonConsumables_Click); } void ucButtonConsumables_Click(object sender,EventArgs e) { MessageBox.Show("Button Clicked") } } 解决方法
从设计器序列化中隐藏Text属性:
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public override string Text { get { return base.Text; } set { base.Text = value; } } 或使用默认值创建设计器: public class ConsumablesButtonDesigner : System.Windows.Forms.Design.ControlDesigner { public override void OnSetComponentDefaults() { base.OnSetComponentDefaults(); Control.Text = "Consumables"; } } 并为您的按钮提供设计师: [Designer(typeof(ConsumablesButtonDesigner))] public class ucButtonConsumables : Button { //... } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- windows – 在同一端口上侦听的多个进程?
- Windows Server 2016-Active Directory域服务概述
- windows – 如何向DHCP服务器添加另一个地址范围
- Windows – 域帐户使用正确的密码每隔几分钟保持锁定
- Windows – 尝试从PGAdmin导入CSV文件时被拒绝
- 在Windows资源管理器中搜索只是文件夹
- 如何在Windows上安装PLV8?
- axapta – Microsoft Dynamics AX 2009发展
- windows-server-2003 – 如何在Windows Server 2003上使用N
- 如何使用命令行界面管理远程Windows Server?