插入符位置 C# Web 表单

发布于 2024-12-29 07:47:27 字数 122 浏览 5 评论 0原文

我在 C# Web 表单上更改文本框中插入符号的位置时遇到问题。我尝试了几种不同的使用 SelectionStart 设置的方法,但每次它都说...WebControls 没有 SelectionStart 的定义。有什么想法吗?

I'm having trouble changing the position of the caret in my textboxes, on a C# webform. I've tried several different ways of using the SelectionStart setting but everytime it says ...WebControls doesn't have a definition for SelectionStart. Any ideas??

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

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

发布评论

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

评论(4

紅太極 2025-01-05 07:47:27

我相信 SelectionStart 仅适用于 System.Windows.Forms。文本框。将这组属性用于 System.Web.UI .WebControls.TextBox

I believe SelectionStart is only available for System.Windows.Forms.TextBox. Use this set of properties for System.Web.UI.WebControls.TextBox

囍孤女 2025-01-05 07:47:27

使用 Javascript 来执行此操作 - Web 控件没有 SelectionStart 属性,因为 Web 控件在服务器上执行,而不是在浏览器中执行。在服务器端设置选择没有多大意义,因为实际的交互控件仅存在于浏览器内部。

如有必要,您可以将隐藏输入字段中的提示从服务器发送到客户端,然后使用一段 Javascript 代码中的提示来更改生成的 input 字段中的选择从您的 TextBox 中。

Use Javascript to do this - the web control doesn't have a SelectionStart property because the web control executes on the server, not in the browser. It doesn't make much sense to set the selection on the server side, since the actual interactive control only exists inside the browser.

If necessary, you can send a hint in a hidden input field from the server to the client-side and then use that hint from a bit of Javascript code to change the selection in the input field that was generated from your TextBox.

苍暮颜 2025-01-05 07:47:27

您无法在服务器端执行此操作,您必须使用客户端 JavaScript 来执行此操作,就像没有 WebForms 一样。

You can't do this on the server-side, you'd have to use client-sided JavaScript, just like without WebForms, to do this.

别理我 2025-01-05 07:47:27

尝试以下代码:

richTextBox1.Select(caret_position, 0);

这里 caret_position 是您要放置插入符的索引

Try the following code:

richTextBox1.Select(caret_position, 0);

Here caret_position is the index at which you want to place caret

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