相关疑难解决方法(0)

WinForms中的水印TextBox

任何人都可以指向一个基本的Windows窗体TextBox的良好实现,它最初会显示水印文本,当光标进入时它会消失吗?我想我可以通过创造性地使用Enter和Leave事件来创建我自己的东西,但我确信在某个地方有一个完全可用的实现.我看到了WPF实现,如果有必要,我可以嵌套它,但原生的WinForms TextBox派生会更好.

到目前为止,我有这个; 尚未尝试过,但有没有人看到任何明显的问题?

public class WatermarkTextBox:TextBox
{
    public string WatermarkText { get; set; }

    public Color WatermarkColor { get; set; }

    private Color TextColor { get; set; }

    private bool isInTransition;

    public WatermarkTextBox()
    {
        WatermarkColor = SystemColors.GrayText;
    }

    private bool HasText { get { return Text.IsNotNullOrBlankOr(WatermarkText); }}

    protected override void OnEnter(EventArgs e)
    {
        base.OnEnter(e);

        if (HasText) return;

        isInTransition = true;
        ForeColor = TextColor;
        Text = String.Empty;
        isInTransition = false;
    }

    protected override void OnForeColorChanged(EventArgs e)
    {
        base.OnForeColorChanged(e);
        if (!isInTransition) …
Run Code Online (Sandbox Code Playgroud)

.net textbox watermark winforms

53
推荐指数
5
解决办法
3万
查看次数

System.Windows.Forms.TextBox中的水印

System.Windows.Forms.TextBox使用C#在.Net 2.0中实现水印功能的最佳方法是什么?


编辑:

使用CodeProject中的现成组件非常简单.它还带有代码项目开放许可证(CPOL).

.net c# windows watermark .net-2.0

14
推荐指数
2
解决办法
2万
查看次数

在C#中单击时清除单个Texbox?

如何制作它,以便在单击文本框时,文本框中最初的文本("在此处输入文本")将被清除,并且仅在第一次单击时被清除?

编辑:对不起,我正在使用C#.

.net c# textbox winforms

2
推荐指数
1
解决办法
1123
查看次数

标签 统计

.net ×3

c# ×2

textbox ×2

watermark ×2

winforms ×2

.net-2.0 ×1

windows ×1