问题:
希望设置TextBox 中的光标到任意位置。

设置SelectStart 和Length 不一地起作用,并不希望选中文本。

解决方案:
使用一下代码就可以

C# tips- 设置文本框光标的位置        [System.Runtime.InteropServices.DllImport("user32.dll")]
C# tips- 设置文本框光标的位置        
public static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);
C# tips- 设置文本框光标的位置 
C# tips- 设置文本框光标的位置        
public void SetCursorPosofTextBox(TextBox txb,int pos)
{
C# tips- 设置文本框光标的位置            txb.Focus();
C# tips- 设置文本框光标的位置            SendMessage(txb
.Handle,177,pos,pos);
C# tips- 设置文本框光标的位置        }

C# tips- 设置文本框光标的位置

调用:

C# tips- 设置文本框光标的位置SetCursorPosofTextBox(this.textBox1,3);        

相关文章:

  • 2021-12-13
  • 2021-08-17
  • 2021-09-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-16
猜你喜欢
  • 2021-08-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案