Skip to content
| Marketplace
Sign in
Visual Studio>Controls>ValueButton
ValueButton

ValueButton

Ms Paint

|
183 installs
| (0) | Free
ValueButton 控件继承标准 Windows 窗体按钮的所有功能,但是公开了一个附加的自定义属性。
Download

此按钮继承标准 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
csharp
label1.Text = valueButton1.ButtonValue.ToString();
label1.Text = valueButton1.ButtonValue.ToString();
 测试方法:

创建测试项目

  1. 在“文件”菜单上,指向“添加”,然后单击“新建项目”打开“添加新项目”对话框。

  2. 在“Visual C#”节点下选择“Windows”节点,再单击“Windows 窗体应用程序”。

  3. 在“名称”框中键入 Test。

  4. 在“解决方案资源管理器”中,右击测试项目的“引用”节点,然后从快捷菜单上选择“添加引用”以显示“添加引用”对话框。

  5. 单击标记为“项目”的选项卡。 “项目名称”下将列出 ValueButtonLib 项目。 双击该项目以将引用添加到测试项目。

  6. 在“解决方案资源管理器”中,右击“测试”并选择“生成”。

     

将控件添加到窗体

  1. 在“解决方案资源管理器”中,右击“Form1.cs”,然后从快捷菜单中选择“视图设计器”。

  2. 在“工具箱”中单击“ValueButtonLib 组件”。 双击“ValueButton”。

    窗体上出现一个“ValueButton”。

  3. 右击“ValueButton”并从快捷菜单中选择“属性”。

  4. 在“属性”窗口中检查该控件的属性。 注意,除增加了一个 ButtonValue 属性外,它们与标准按钮公开的属性相同。

  5. 将 ButtonValue 属性设置为 5。

  6. 在“工具箱”的“所有 Windows 窗体”选项卡中,双击“标签”,将 Label 控件添加到窗体中。

  7. 将标签重新定位到窗体的中央。

  8. 双击 valueButton1。

    将响应 valueButton1_Click 事件而打开“代码编辑器”。

  9. 插入下面的代码行。

    C#
    编辑脚本|Remove
    csharp
    label1.Text = valueButton1.ButtonValue.ToString();
    label1.Text = valueButton1.ButtonValue.ToString();

  10. 在“解决方案资源管理器”中,右击“测试”,然后从快捷菜单中选择“设为启动项目”。

  11. 从“调试”菜单中选择“启动调试”。

    Form1 出现。

  12. 单击 valueButton1。

    label1 中显示数字“5”,说明继承控件的 ButtonValue 属性已经通过 valueButton1_Click 方法传递到 label1。 这样,ValueButton 控件便继承了标准 Windows 窗体按钮的所有功能,但是公开了一个附加的自定义属性。

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft