此按钮继承标准 Windows 窗体 Button 控件的功能,并公开一个名为 ButtonValue 的自定义属性。ValueButton控件从 Windows 窗体控件继承。ValueButton控件仿效了Button,但是公开了一个附加的自定义属性ButtonValue,经"Test"项目测试成功。ButtonValue属性定义如下: C# 编辑脚本|Remove csharp// Creates the private variable that will store the value of your // property. private int varValue; // Declares the property. public int ButtonValue { // Sets the method for retrieving the value of your property. get { return varValue; } // Sets the method for setting the value of your property. set { varValue = value; } // Creates the private variable that will store the value of your // property. private int varValue; // Declares the property. public int ButtonValue { // Sets the method for retrieving the value of your property. get { return varValue; } // Sets the method for setting the value of your property. set { varValue = value; } 测试代码如下: C# 编辑脚本|Remove csharplabel1.Text = valueButton1.ButtonValue.ToString(); label1.Text = valueButton1.ButtonValue.ToString(); 测试方法: 创建测试项目
将控件添加到窗体
|