Public Partial Class Watertextbox: textbox { Private Readonly Label lblwatertext = New Label (); Public Watertextbox () {initializecomponent (); lblwatertext. borderstyle = borderstyle. None; lblwatertext. Enabled = False ; Lblwatertext. backcolor = color. White; lblwatertext. autosize = False ; Lblwatertext. Top = 1; lblwatertext. Left = 2; lblwatertext. flatstyle = flatstyle. system; controls. Add (lblwatertext);} [category ( "Extended attributes" ), Description ( "Displayed prompt information" )] Public String Watertext {get { Return Lblwatertext. Text;} set {lblwatertext. Text = Value ;}} Public Override String Text {set {lblwatertext. Visible =Value = String . Empty; Base . Text = Value ;} Get { Return Base . Text ;}} Protected Override Void Onsizechanged (eventargs e ){ If (Multiline & (scrollbars = scrollbars. Vertical | scrollbars = scrollbars. Both) lblwatertext. width = width-20; Else Lblwatertext. width = width; lblwatertext. Height = height-2; Base . Onsizechanged (E );} Protected Override Void Ontextchanged (eventargs e) {lblwatertext. Visible = Base . Text = String . Empty; Base . Ontextchanged (E );} Protected Override Void Onmousedown (mouseeventargs e) {lblwatertext. Visible =False ; Base . Onmousedown (E );} Protected Override Void Onmouseleave (eventargs e) {lblwatertext. Visible = Base . Text = String . Empty; Base . Onmouseleave (E );} // Protected override void onenter (eventargs E) //{ // Lblwatertext. Visible = false; // Base. onenter (E ); //} // Protected override void onleave (eventargs E) //{ // If (string. isnullorempty (base. Text )) // Lblwatertext. Visible = true; // Base. onleave (E ); //} }
Add a method (for conversion ):
Public partial class prompttextbox: textbox
{
Private string promptstring = string. empty;
Private bool isempty = true;
Public prompttextbox ()
{
Initializecomponent ();
}
Public prompttextbox (string prompt)
{
Initializecomponent ();
Promptstring = prompt;
}
/**/
/// <Summary>
/// Prompt text
/// </Summary>
Public String promptstring
{
Get {return promptstring ;}
Set {promptstring = value ;}
}
Protected override void onenter (eventargs E)
{
If (isempty) {clear ();}
}
Protected override void onleave (eventargs E)
{
If (text = string. Empty)
{
TEXT = promptstring;
Isempty = true;
}
Else {isempty = false ;}
}
Public override string text
{
Get
{
If (isempty) {return string. Empty ;}
Else {return base. Text ;}
}
Set
{
If (value = string. Empty)
{
Base. Text = promptstring;
Isempty = true;
}
Else
{
Isempty = (value = promptstring );
Base. Text = value;
}
}
}
Protected override void oncreatecontrol ()
{
If (text = string. Empty)
{
TEXT = promptstring;
Isempty = true;
}
Else {isempty = false ;}
}
}