【问题标题】:C# WindowsForm - How Detect if focus enter in textbox was by mouse click or tabC# Windows 窗体 - 如何检测是否通过鼠标单击或选项卡在文本框中输入焦点
【发布时间】:2013-04-18 06:06:31
【问题描述】:

如果里面已经写了一些东西(TextLength > 0),我有这个代码来选择文本框中的所有文本,当我使用此文本框上的选项卡聚焦输入时,它工作完美,然后全选或不全选,聚焦时的小问题是通过鼠标单击制作,所以我只想在焦点输入不是通过鼠标单击时执行下面的代码,因为如果鼠标单击文本框并且它已经有文本,它将全选大约 0,1 秒并取消选择(但用户可以查看蓝色选择文本而不是取消选择后),它不是很好

我的代码:

private void txtValormetrocubico_Enter(object sender, EventArgs e)
{
    if (txtValormetrocubico.TextLength > 0)
    {
        txtValormetrocubico.SelectAll();
    }
}

我想做什么(语法不正确,只是为了理解我的目标)

    private void txtValormetrocubico_Enter(object sender, EventArgs e)
    {
        if (isnt mouse_click)
        {
            if (txtValormetrocubico.TextLength > 0)
            {
                txtValormetrocubico.SelectAll();
            }
        } 
    }

谢谢

【问题讨论】:

    标签: c# textbox click focus


    【解决方案1】:

    在表单的构造函数中,您可以挂钩GotFocus 事件

    public Form1()
    {
        textBox1.GotFocus += textBox1_GotFocus;
    }
    
    void textBox1_GotFocus(object sender, EventArgs e)
    {
        throw new NotImplementedException();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-21
      • 2018-10-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多