50% OFF!!!

Sunday, November 14, 2010

C# | Winforms | Textbox within Button

Here is an example for creating a Button control which contains a Textbox inside it.
This is very usefull when the button functionality is based (only) on the textbox content text, and it is very usefull for the user.

Screenshot (image) example:


The Code:
class ButtonWithTextbox : Button
{
    TextBox _textbox = new TextBox();

    public int TextboxWidth
    {
        get { return _textbox.Width; }
        set { _textbox.Width = value; }
    }
    public Point TextboxLocation
    {
        get { return _textbox.Location; }
        set { _textbox.Location = value; }
    }
    /** And we may add all properties of the Textbox ***/

    public ButtonWithTextbox()
    {
        this.Controls.Add(_textbox);
    }
}

Also work great on the designer... :)

MDB-Blog
http://mdb-blog.blogspot.com

1 comment: