如何将光标移动到文本末尾(Delphi)?

发布于 2024-09-26 22:32:16 字数 173 浏览 4 评论 0原文

这是我使用 SendMessage 函数填充文本框的代码:

  C := 'Hey there';
  SendMessage(h1, WM_SETTEXT, 1, Integer(PChar(C)));

现在,如何将光标移动到文本末尾?

This is my code to fill a TextBox using the SendMessage function:

  C := 'Hey there';
  SendMessage(h1, WM_SETTEXT, 1, Integer(PChar(C)));

Now, how can I move the cursor to the end of the text?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

澉约 2024-10-03 22:32:16

如果您确实想对消息执行此操作,请查看:

  1. EM_SETSEL
  2. EM_EXSETSEL

此外,您还有完整的编辑参考:

http://msdn.microsoft.com/en-us/library/ff485923%28v=VS.85%29.aspx

在代码中(无消息),您将执行如下操作:

Edit1.SelLength := 0;
Edit1.SelStart := 0;   // set caret before first character
...
Edit1.SelStart := 1;   // set caret before second character
...
Edit1.SelStart := Length(Edit1.Text) // set caret after the last character

对于消息:

SendMessage(h1, EM_SETSEL, Length(C), Length(C));

If you really want to do this with messages take a look at:

  1. EM_SETSEL
  2. EM_EXSETSEL

Also there you have the complete reference for edit:

http://msdn.microsoft.com/en-us/library/ff485923%28v=VS.85%29.aspx

In code (no messages) you would do something like this:

Edit1.SelLength := 0;
Edit1.SelStart := 0;   // set caret before first character
...
Edit1.SelStart := 1;   // set caret before second character
...
Edit1.SelStart := Length(Edit1.Text) // set caret after the last character

With messages:

SendMessage(h1, EM_SETSEL, Length(C), Length(C));
澜川若宁 2024-10-03 22:32:16

我认为你的代码是错误的。您必须使用“EM_SETSEL”参数。我的问题用这段代码解决了:

  //Set a value for external textbox
  SendMessage(h1, WM_SETTEXT, 0, Integer(PChar(C)));
  //move the cursor to end of the textbox(editbox,field,...)
  SendMessage(h1, EM_SETSEL, length(C), length(C));

无论如何,谢谢你:)

I think your code is wrong . you have to using "EM_SETSEL" parameter . my problem solved with this code :

  //Set a value for external textbox
  SendMessage(h1, WM_SETTEXT, 0, Integer(PChar(C)));
  //move the cursor to end of the textbox(editbox,field,...)
  SendMessage(h1, EM_SETSEL, length(C), length(C));

Thank you , anyway :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文