【问题标题】:How do I stop the text in a Winforms textbox from being automatically selected/highlighted when first displayed?如何阻止 Winforms 文本框中的文本在首次显示时被自动选择/突出显示?
【发布时间】:2018-09-11 20:31:03
【问题描述】:

如果我不希望用户在第一次加载和显示文本框时无意中删除文本框中显示的文本,例如,无意中在键盘上摸索,我该如何停止文本框中的文本文本框在首次显示时和用户访问之前被自动选中?

【问题讨论】:

    标签: c# winforms textbox highlight


    【解决方案1】:

    将要禁用突出显示的文本框的 tabstop 属性设置为 false -

    textBox1.TabStop = false;
    

    这将停止突出显示文本框的文本。

    【讨论】:

    • 这确实有效,但是当对话框出现时光标是不可见的。我认为它应该在文本框中可见
    • 你能详细说明你现在面临的确切问题是什么
    • 哦,对不起 - 没问题。我的目的是回答我自己的问题,以使知识可用,以便其他人(包括我自己)以后可以找到它。我必须等待两天才能回答我自己的问题。
    【解决方案2】:
    //set SelectionStart property to zero
    //This clears the selection and sets the cursor to the left of the 1st character in the textbox
    textBox1.SelectionStart = 0;
    
    //This clears the selection and sets the cursor to the end of whatever is in the textbox
    textBox1.SelectionStart = textBox1.Text.Length;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-22
      • 2023-04-04
      • 2010-10-18
      • 2011-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-20
      相关资源
      最近更新 更多