<tfoot id='hCaT3'></tfoot>

    • <bdo id='hCaT3'></bdo><ul id='hCaT3'></ul>

    1. <legend id='hCaT3'><style id='hCaT3'><dir id='hCaT3'><q id='hCaT3'></q></dir></style></legend>

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

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

        获取文本框中所选文本在字符串中的位置

        Get position of selected text in string in textbox(获取文本框中所选文本在字符串中的位置)

            <bdo id='3fzFo'></bdo><ul id='3fzFo'></ul>

          • <small id='3fzFo'></small><noframes id='3fzFo'>

            <legend id='3fzFo'><style id='3fzFo'><dir id='3fzFo'><q id='3fzFo'></q></dir></style></legend>
                <tfoot id='3fzFo'></tfoot>

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

                    <tbody id='3fzFo'></tbody>
                  本文介绍了获取文本框中所选文本在字符串中的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  好的,我正在尝试在这里做一些具体的事情.我想在文本框中获取所选文本的位置.

                  Ok, I'm trying to do something a little specific here. I want to get the location of the selected text in a textbox.

                  详细说明-我可以使用位置来选择文本.如果我有一个 textBox1 我可以这样做:

                  To elaborate- I can use location to select text. If I have a textBox1 I could do:

                  textBox1.SelectionStart = 1;
                  textBox1.SelectionLength = 4;
                  

                  这将从第二个字母开始并选择 4 个字母.

                  That would start at the second letter and select 4 letters.

                  我想做的恰恰相反:当用户选择文本时,我想找出开始是什么,长度是多少(或者开始是什么,结束是什么.两者都行).

                  What I want to do is the opposite: when the user selects text, I want to find out what the start is and what the length is (or what the start is and what the end is. Either will work).

                  我想过只在字符串中搜索选定文本 (textBox1.SelectedText).如果它是一个常用词或多次使用的字符串,就会出现问题.例如.

                  I thought about just searching the string for the selectedtext (textBox1.SelectedText). The problem comes if it is a common word or a string that is used multiple times. For instance.

                  这是一只猫.这是一只猫.这是一只猫.

                  This is a cat. This is a cat. This is a cat.

                  如果他们选择第二个句子,使用 SelectedText 搜索该特定句子的字符串对我没有好处.它可以是 3 个中的任何一个.

                  If they select the second sentence, using SelectedText to search the string for that specific sentence does me no good. It could be either of the 3.

                  所以,我的问题是:当用户点击一个按钮时,我如何确定用户选择的确切元素,以便我以后可以操作这些特定元素?重要的是要注意后面的部分-我可能不仅想在按下按钮时操作文本.我还想稍后再操作它,此时文本可能不再突出显示.这意味着我要存储一些东西来告诉我我正在处理的句子的具体部分.如果该解决方案不可行,是否有您可以想到的解决方案,在上面的这是一只猫"示例中,用户可以选择第二个句子,点击一个按钮,然后我知道选择了哪个句子当他按下那个按钮时?

                  So, my question is: When the user clicks a button, how do I determine the exact elements that are selected by the user, so that I can later manipulate those specific elements? Important to note the later part- I likely will not only want to manipulate the text when the button is pressed. I will also want to manipulate it later, at a time when the text may no longer be highlighted. This means I'll want to store SOMETHING to tell me what specific parts of the sentence I'm dealing with. If that solution isn't viable, is there a solution you can think of where, in the above "this is a cat" example, the user could select the second sentence, hit a button, and then later I know which sentence was selected when he hit that button?

                  推荐答案

                  根据documentation、SelectionStartSelectionLength 都可以设置和读取.就用那些吧.

                  According to the documentation, SelectionStart and SelectionLength can be both set and read. Just use those.

                  这篇关于获取文本框中所选文本在字符串中的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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# 纯数字文本框控件)
                  • <tfoot id='0aMtr'></tfoot>

                    <small id='0aMtr'></small><noframes id='0aMtr'>

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

                          <legend id='0aMtr'><style id='0aMtr'><dir id='0aMtr'><q id='0aMtr'></q></dir></style></legend>
                              <tbody id='0aMtr'></tbody>