开发者

How to make a visual reuasable class in C#?(Visual Studio 2010)

开发者 https://www.devze.com 2023-01-11 05:27 出处:网络
i have this class for example: class labeledtext { private TextBox tb; private Label l; public labeledtext(Form frm)

i have this class for example:

class labeledtext
{
    private TextBox tb;
    private Label l;
    public labeledtext(Form frm)
    {
        tb = new TextBox();
        l = new Label();
        frm.Controls.Add(tb);
        frm.Controls.Add(l);
    }
    public void SetCaption(string cpt)
    {
        l.Text = cpt;
    }
    public string text()
    {
        return tb.Text;
    }
}

I want to make an object from this class, that can be used in any other project, as a visual object. I want to use it like a text box, drag it from toolbox开发者_运维技巧 to my form and put it and so on. how can i do this? I use visual studio 2010, if it is important.


I think you're looking for a user control.

In the solution explorer, right click, new usercontrol.

You can draw it in design time, and you can drag it wherever you want. (It will appear in the toolbar after you build the solution).

Here is a little guide: LINK

0

精彩评论

暂无评论...
验证码 换一张
取 消