• <i id='dayKi'><tr id='dayKi'><dt id='dayKi'><q id='dayKi'><span id='dayKi'><b id='dayKi'><form id='dayKi'><ins id='dayKi'></ins><ul id='dayKi'></ul><sub id='dayKi'></sub></form><legend id='dayKi'></legend><bdo id='dayKi'><pre id='dayKi'><center id='dayKi'></center></pre></bdo></b><th id='dayKi'></th></span></q></dt></tr></i><div id='dayKi'><tfoot id='dayKi'></tfoot><dl id='dayKi'><fieldset id='dayKi'></fieldset></dl></div>

      <small id='dayKi'></small><noframes id='dayKi'>

    1. <legend id='dayKi'><style id='dayKi'><dir id='dayKi'><q id='dayKi'></q></dir></style></legend>
          <bdo id='dayKi'></bdo><ul id='dayKi'></ul>

      1. <tfoot id='dayKi'></tfoot>

        文本框不可点击但可编辑

        Textbox not clickable but editable(文本框不可点击但可编辑)

          <i id='et8ox'><tr id='et8ox'><dt id='et8ox'><q id='et8ox'><span id='et8ox'><b id='et8ox'><form id='et8ox'><ins id='et8ox'></ins><ul id='et8ox'></ul><sub id='et8ox'></sub></form><legend id='et8ox'></legend><bdo id='et8ox'><pre id='et8ox'><center id='et8ox'></center></pre></bdo></b><th id='et8ox'></th></span></q></dt></tr></i><div id='et8ox'><tfoot id='et8ox'></tfoot><dl id='et8ox'><fieldset id='et8ox'></fieldset></dl></div>

          <tfoot id='et8ox'></tfoot>
        • <small id='et8ox'></small><noframes id='et8ox'>

            <tbody id='et8ox'></tbody>

                <legend id='et8ox'><style id='et8ox'><dir id='et8ox'><q id='et8ox'></q></dir></style></legend>
                • <bdo id='et8ox'></bdo><ul id='et8ox'></ul>

                  本文介绍了文本框不可点击但可编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个带有 10 个文本框的小表单,我将它们设置在正确的 Tab Order 中,目前我希望它们按 Tab To 的方式设置.我想知道是否有一种方法可以设置文本框,以便除非它们被标签进入,否则它们不能被选中进行编辑.即...我不希望最终用户能够单击文本框来编辑它们,我只希望它们可以通过 Tabbing 编辑.

                  I have a small form with 10 textboxes, I have them set in the right Tab Order currently the way I want them to Tab To. I was wondering if there is a way to set the textboxes up so they cannot be selected for editing unless they are Tabbed into. ie... I don't want the end user to be able to click on the textbox to edit them, I only want them editable through Tabbing.

                  推荐答案

                  这应该可以解决问题

                  public partial class PoorTextBox : TextBox
                  {
                      protected override void WndProc(ref Message m)
                      {
                          if (m.Msg == (int) WM.LBUTTONDOWN)
                          {
                              return;//Eat mouse down events 
                          }
                          base.WndProc(ref m);
                      }
                  }
                  

                  可以在这里找到窗口消息枚举.<小时>如何在不继承 TextBox 的情况下做到这一点:

                  Window messages enum can be found here.


                  How to do it without inheriting TextBox :

                  class EatMouseDown : NativeWindow
                  {
                      protected override void WndProc(ref Message m)
                      {
                          if (m.Msg == (int)WM.LBUTTONDOWN)
                          {
                              return;
                          }
                          base.WndProc(ref m);
                      }
                  }
                  
                  protected override void OnLoad(EventArgs e)
                  {
                      base.OnLoad(e);
                  
                      new EatMouseDown().AssignHandle(textBox1.Handle);//Subclass a Handle
                  }
                  

                  <小时>如何在没有任何继承的情况下做到这一点:


                  How to do it without any inheritance:

                  省略了清理部分,这也很重要.这可能是错误的,但有效.推荐的方式是使用继承.从 .net fw src 中提取的所需方法.

                  Clean up part omitted, which is also important. This may be buggy but that works. Recommended way is to use inheritance. Required methods pulled from .net fw src.

                  class EatMouseDown
                  {
                      public delegate IntPtr WndProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
                  
                      #region External methods...
                  
                      [DllImport("user32.dll", CharSet = CharSet.Auto)]
                      public static extern IntPtr SetWindowLong(HandleRef hWnd, int nIndex, WndProc wndproc);
                  
                      [DllImport("user32.dll", CharSet = CharSet.Auto)]
                      public static extern IntPtr SetWindowLongPtr(HandleRef hWnd, int nIndex, WndProc wndproc);
                  
                      [DllImport("user32.dll", CharSet = CharSet.Auto)]
                      public static extern IntPtr GetWindowLong(HandleRef hWnd, int nIndex);
                  
                      [DllImport("user32.dll", CharSet = CharSet.Auto)]
                      public static extern IntPtr GetWindowLongPtr(HandleRef hWnd, int nIndex);
                  
                      [DllImport("user32.dll", CharSet = CharSet.Auto)]
                      public static extern IntPtr DefWindowProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
                  
                      [DllImport("user32.dll", CharSet = CharSet.Auto)]
                      public static extern IntPtr CallWindowProc(IntPtr wndProc, IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
                  
                      #endregion
                  
                      private const int GWLP_WNDPROC = -4;
                      private IntPtr handle;
                      private IntPtr originalWndProc;
                      private IntPtr currentWndProc;
                  
                      public static IntPtr SetWindowLongHelper(HandleRef hWnd, int nIndex, WndProc wndProc)
                      {
                          return IntPtr.Size == 4
                              ? SetWindowLong(hWnd, nIndex, wndProc)
                              : SetWindowLongPtr(hWnd, nIndex, wndProc);
                      }
                  
                      public static IntPtr GetWindowLongHelper(HandleRef hWnd, int nIndex)
                      {
                          return IntPtr.Size == 4
                              ? GetWindowLong(hWnd, nIndex)
                              : GetWindowLongPtr(hWnd, nIndex);
                      }
                  
                      internal void SubclassHandle(IntPtr handle)
                      {
                          this.handle = handle;
                          this.originalWndProc = GetWindowLongHelper(new HandleRef(this, handle), GWLP_WNDPROC);
                          SetWindowLongHelper(new HandleRef(this, handle), GWLP_WNDPROC, new WndProc(this.Callback));
                          this.currentWndProc = GetWindowLongHelper(new HandleRef(this, handle), GWLP_WNDPROC);
                      }
                  
                      private IntPtr Callback(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam)
                      {
                          var m = Message.Create(hwnd, msg, wparam, lparam);
                          if (m.Msg == (int)WM.LBUTTONDOWN)
                          {
                              return IntPtr.Zero;
                          }
                          return CallWindowProc(originalWndProc, hwnd, msg, wparam, lparam);
                      }
                  }
                  
                  protected override void OnLoad(EventArgs e)
                  {
                      base.OnLoad(e);
                  
                      new EatMouseDown().SubclassHandle(textBox1.Handle);//Subclass a Handle
                  }
                  

                  这篇关于文本框不可点击但可编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to keep the Text of a Read only TextBox after PostBack()?(PostBack()之后如何保留只读文本框的文本?)
                  Winforms Textbox - Using Ctrl-Backspace to Delete Whole Word(Winforms 文本框 - 使用 Ctrl-Backspace 删除整个单词)
                  C# - Add button click events using code(C# - 使用代码添加按钮单击事件)
                  Multi-color TextBox C#(多色文本框 C#)
                  How can i set the caret position to a specific index in passwordbox in WPF(如何将插入符号位置设置为 WPF 密码框中的特定索引)
                  C# Numeric Only TextBox Control(C# 纯数字文本框控件)

                      <tbody id='fZV7w'></tbody>
                  1. <i id='fZV7w'><tr id='fZV7w'><dt id='fZV7w'><q id='fZV7w'><span id='fZV7w'><b id='fZV7w'><form id='fZV7w'><ins id='fZV7w'></ins><ul id='fZV7w'></ul><sub id='fZV7w'></sub></form><legend id='fZV7w'></legend><bdo id='fZV7w'><pre id='fZV7w'><center id='fZV7w'></center></pre></bdo></b><th id='fZV7w'></th></span></q></dt></tr></i><div id='fZV7w'><tfoot id='fZV7w'></tfoot><dl id='fZV7w'><fieldset id='fZV7w'></fieldset></dl></div>
                    • <legend id='fZV7w'><style id='fZV7w'><dir id='fZV7w'><q id='fZV7w'></q></dir></style></legend>

                      1. <tfoot id='fZV7w'></tfoot>

                          <bdo id='fZV7w'></bdo><ul id='fZV7w'></ul>

                            <small id='fZV7w'></small><noframes id='fZV7w'>