hello
i made a class that inherite from text box.
i have a Textbox that receives a button as Clean button. then a function is added to this button's events.
this function clean content of textbox.
but my code dose'nt work.
public partial class MyTxt : TextBox
{
public MyTxt()
{
InitializeComponent();
}public MyTxt(IContainer container)
{
container.Add
this);
InitializeComponent();
CleanButton =
new Button();
CleanButton.Click +=new EventHandler(CleanTxt);
}
public void CleanTxt(object sender, EventArgs e)
{
this.Text = "";
}
private Button _CleanButton ;
public Button CleanButton
{
get { return _CleanButton; }
set { _CleanButton = value; }
}
}
zozo mehrPosted Feb 19, 2013, 2:24 PM
i put Vb cod:
Upamanyu Roy ChoudhuryPosted Feb 19, 2013, 1:18 PM
Instead of writing code this create an user control first to be used in your applcation or a custom control to be used by mutliple appliocations. In that controls class inherit the textBox class and then ovveride the existing properties and methods if you want to and add new members in your class.
Write the code like following in your usercontrol and then drag and drop it in your consuming Winbdows Form and then access its properties and then use the metod for clear which is C
ClearText() in my application.
While creating the usercontrol drag and drop a textbox in it and name it as myText.
If you find any issues let me know.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class MyTextBox : System.Windows.Forms.TextBox{
private string _textVal;
public string SetText
{
set{
_textVal = value;
}
}
public string GetText
{
get{
return _textVal;
}
}
public MyTextBox()
{
InitializeComponent();
}
public void ClearText()
{
this.myText.Text = "";
}
}
}
To dig into the deep use the following link
http://www.codeproject.com/Questions/520266/inheritplustextboxpluscontrolplus-c-23
If you find my post as useful then please mark it as an answer