如何从属性中创建自定义 [英] how to create custom from propery

查看:71
本文介绍了如何从属性中创建自定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在c#.net中创建自定义表单属性

请帮助我

I want to create a custom form property in c# .net

Please help me

推荐答案

您是说要向Form类本身添加属性?如果是这样,您就不能,但是有两个简单的解决方案.

1.创建一个从Form派生的新类,并在需要时使用它.
Do you mean add a property to the Form class itself? If so, you can''t but there are two easy solutions.

1. Create a new class derived from Form and use that in place when you need it.
public class MyFormBase : Form
{
    // ...
    private int id;

    /// <summary>
    /// Gets or sets the identifier.
    /// </summary>
    public int ID
    {
        get{ return id; }
        set{ id = value; }
    }
}


因此,在添加新表单时,请更改声明


So when adding a new form, change the declaration

public partial class Form1 : MyFormBase
{
    // ...
    // Form1 instances automatically have ID property
}



2.使用扩展方法 [



2. Use Extension Methods[^]


只需添加它即可.如果您在执行此操作时遇到特定问题,请发布代码并进行解释.
Just add it. If you have a specific issue with doing so, post your code and explain it.


这篇关于如何从属性中创建自定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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