using System;
using System.Collections .Generic ;
using System.Linq ;
using System.Text ;
using System.ComponentModel ;
using System.Windows .Forms ;
using System.Drawing ;
namespace WindowsFormsApplication2
{
[ DesignerCategory( "Default" ) ]
class TextBoxEx : TextBox
{
public TextBoxEx( )
{
Watermark = "" ;
}
public string Watermark { get; set; }
private bool ShowsWatermark
{
get { return ! DesignMode && ! Focused && Text == "" ; }
}
private Color WatermarkColor
{
get { return SystemColors.GrayText ; }
}
protected override void WndProc( ref Message m)
{
base.WndProc ( ref m) ;
const int WM_PAINT = 0x000f ;
switch ( m.Msg )
{
case WM_PAINT:
if ( ShowsWatermark)
{
PrintWatermark( ) ;
}
break ;
}
}
private void PrintWatermark( )
{
using ( var g = CreateGraphics( ) )
{
//using (var br = new SolidBrush(BackColor))
//{
// g.FillRectangle(br, this.ClientRectangle);
//}
using ( var br = new SolidBrush( WatermarkColor) )
{
var sf = new StringFormat( ) ;
g.DrawString ( Watermark, Font, br, ClientRectangle, sf) ;
}
}
}
}
}
dXNpbmcgU3lzdGVtOwoKdXNpbmcgU3lzdGVtLkNvbGxlY3Rpb25zLkdlbmVyaWM7Cgp1c2luZyBTeXN0ZW0uTGlucTsKCnVzaW5nIFN5c3RlbS5UZXh0OwoKdXNpbmcgU3lzdGVtLkNvbXBvbmVudE1vZGVsOwoKdXNpbmcgU3lzdGVtLldpbmRvd3MuRm9ybXM7Cgp1c2luZyBTeXN0ZW0uRHJhd2luZzsKCgoKbmFtZXNwYWNlIFdpbmRvd3NGb3Jtc0FwcGxpY2F0aW9uMgoKewoKICAgIFtEZXNpZ25lckNhdGVnb3J5KCJEZWZhdWx0IildCgogICAgY2xhc3MgVGV4dEJveEV4IDogVGV4dEJveAoKICAgIHsKCiAgICAgICAgcHVibGljIFRleHRCb3hFeCgpCgogICAgICAgIHsKCiAgICAgICAgICAgIFdhdGVybWFyayA9ICIiOwoKICAgICAgICB9CgoKCiAgICAgICAgcHVibGljIHN0cmluZyBXYXRlcm1hcmsgeyBnZXQ7IHNldDsgfQoKCgogICAgICAgIHByaXZhdGUgYm9vbCBTaG93c1dhdGVybWFyawoKICAgICAgICB7CgogICAgICAgICAgICBnZXQgeyByZXR1cm4gIURlc2lnbk1vZGUgJiYgICFGb2N1c2VkICYmIFRleHQgPT0gIiI7IH0KCiAgICAgICAgfQoKCgogICAgICAgIHByaXZhdGUgQ29sb3IgV2F0ZXJtYXJrQ29sb3IKCiAgICAgICAgewoKICAgICAgICAgICAgZ2V0IHsgcmV0dXJuIFN5c3RlbUNvbG9ycy5HcmF5VGV4dDsgfQoKICAgICAgICB9CgoKCiAgICAgICAgcHJvdGVjdGVkIG92ZXJyaWRlIHZvaWQgV25kUHJvYyhyZWYgTWVzc2FnZSBtKQoKICAgICAgICB7CgogICAgICAgICAgICBiYXNlLlduZFByb2MocmVmIG0pOwoKCgogICAgICAgICAgICBjb25zdCBpbnQgV01fUEFJTlQgPSAweDAwMGY7CgogICAgICAgICAgICBzd2l0Y2ggKG0uTXNnKQoKICAgICAgICAgICAgewoKICAgICAgICAgICAgICAgIGNhc2UgV01fUEFJTlQ6CgogICAgICAgICAgICAgICAgICAgIGlmIChTaG93c1dhdGVybWFyaykKCiAgICAgICAgICAgICAgICAgICAgewoKICAgICAgICAgICAgICAgICAgICAgICAgUHJpbnRXYXRlcm1hcmsoKTsKCiAgICAgICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgICAgICAgICBicmVhazsKCiAgICAgICAgICAgIH0KCiAgICAgICAgfQoKCgogICAgICAgIHByaXZhdGUgdm9pZCBQcmludFdhdGVybWFyaygpCgogICAgICAgIHsKCiAgICAgICAgICAgIHVzaW5nICh2YXIgZyA9IENyZWF0ZUdyYXBoaWNzKCkpIAoKICAgICAgICAgICAgewoKICAgICAgICAgICAgICAgIC8vdXNpbmcgKHZhciBiciA9IG5ldyBTb2xpZEJydXNoKEJhY2tDb2xvcikpCgogICAgICAgICAgICAgICAgLy97CgogICAgICAgICAgICAgICAgLy8gICAgZy5GaWxsUmVjdGFuZ2xlKGJyLCB0aGlzLkNsaWVudFJlY3RhbmdsZSk7CgogICAgICAgICAgICAgICAgLy99CgoKCiAgICAgICAgICAgICAgICB1c2luZyAodmFyIGJyID0gbmV3IFNvbGlkQnJ1c2goV2F0ZXJtYXJrQ29sb3IpKQoKICAgICAgICAgICAgICAgIHsKCiAgICAgICAgICAgICAgICAgICAgdmFyIHNmID0gbmV3IFN0cmluZ0Zvcm1hdCgpOwoKICAgICAgICAgICAgICAgICAgICBnLkRyYXdTdHJpbmcoV2F0ZXJtYXJrLCBGb250LCBiciwgQ2xpZW50UmVjdGFuZ2xlLCBzZik7CgogICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgfQoKICAgICAgICB9CgogICAgfQoKfQoK
compilation info
prog.cs(11,14): error CS0234: The type or namespace name `Windows' does not exist in the namespace `System'. Are you missing an assembly reference?
prog.cs(61,45): error CS0246: The type or namespace name `Message' could not be found. Are you missing a using directive or an assembly reference?
Compilation failed: 2 error(s), 0 warnings
stdout