【问题标题】:Disable First Line of a TextBox in WPF Application在 WPF 应用程序中禁用文本框的第一行
【发布时间】:2014-09-07 16:18:21
【问题描述】:

如何在 WPF 应用程序中禁用 TextBox 的第一行?

有没有可能?

【问题讨论】:

  • 你为什么需要那个?

标签: c# wpf textbox readonly


【解决方案1】:

将第一行文本放入单独的禁用控件中。

【讨论】:

    【解决方案2】:

    我能想到的唯一方法是监视 SelctionChanged 事件以及退格键。试试这样的。

        private void textbox1_SelectionChanged(object sender, RoutedEventArgs e)
        {
            if (textbox1.GetLineIndexFromCharacterIndex(textbox1.SelectionStart) == 0)
                textbox1.SelectionStart = textbox1.GetLineText(0).Length;
        }
    
        private void textbox1_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Back && textbox1.SelectionStart == textbox1.GetLineText(0).Length)
                e.Handled = true;
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-08
      • 1970-01-01
      • 2015-10-07
      相关资源
      最近更新 更多