I think this does pretty much what you need:
public class MyTextBox : TextBox
{
public const int WM_PAINT = 0x000F;
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM_PAINT:
Invalidate();
base.WndProc(ref m);
if (!ContainsFocus && string.IsNullOrEmpty(Text))
{
Graphics gr = CreateGraphics();
StringFormat format = new StringFormat();
format.Alignment = StringAlignment.Far;
gr.DrawString("Enter your name", Font, new SolidBrush(Color.FromArgb(70, ForeColor)), ClientRectangle, format);
}
break;
default:
base.WndProc(ref m);
break;
}
}
}
Overriding OnPaint on a TextBox is usually not a good idea because the position of the caret will be calculated wrong.
Please notice that the label is shown only when the TextBox is empty and does not have the focus. But this is how most of such input boxes behave.
If the cue should be visible all the time you can just add it as a label:
public class MyTextBox : TextBox
{
private Label cueLabel;
public TextBoxWithLabel()
{
SuspendLayout();
cueLabel = new Label();
cueLabel.Anchor = AnchorStyles.Top | AnchorStyles.Right;
cueLabel.AutoSize = true;
cueLabel.Text = "Enter your name";
Controls.Add(cueLabel);
cueLabel.Location = new Point(Width - cueLabel.Width, 0);
ResumeLayout(false);
PerformLayout();
}
}