winfrom默認是不支持這種操作的,此時需要重寫控件操作,具體代碼如下:
public class TextBoxEx : TextBox
{
public String PlaceHolderStr { get; set; }
protected override void OnPaint(PaintEventArgs e)
{
//
if (!String.IsNullOrEmpty(this.PlaceHolderStr))
{
//坐標位置 0,0 需要根據對齊方式重新計算.
e.Graphics.DrawString(this.PlaceHolderStr, this.Font, new SolidBrush(Color.LightGray), 0, 0);
}
else
{
base.OnPaint(e);
}
}
}
然后在Designer.cs即設計器里面實現該重寫的控件
this.ADTextBox = new frmInfoBarCodeFeeDetailed.TextBoxEx();
然后控件屬性就會出現
所重寫的屬性了,設置即可
完畢!!!
原創作品,轉載請注明出處!!!
如果您覺得這篇博客對您產生了一些必要的幫助, 歡迎您對我意思意思, 我將會覺得您非常夠意思!

