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

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

      <tfoot id='wJ8PE'></tfoot>

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

        在文本框中单击即可选择点击的单词

        时间:2023-06-09

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

              <tbody id='uh8VR'></tbody>

                <legend id='uh8VR'><style id='uh8VR'><dir id='uh8VR'><q id='uh8VR'></q></dir></style></legend>
                  <bdo id='uh8VR'></bdo><ul id='uh8VR'></ul>
                  <i id='uh8VR'><tr id='uh8VR'><dt id='uh8VR'><q id='uh8VR'><span id='uh8VR'><b id='uh8VR'><form id='uh8VR'><ins id='uh8VR'></ins><ul id='uh8VR'></ul><sub id='uh8VR'></sub></form><legend id='uh8VR'></legend><bdo id='uh8VR'><pre id='uh8VR'><center id='uh8VR'></center></pre></bdo></b><th id='uh8VR'></th></span></q></dt></tr></i><div id='uh8VR'><tfoot id='uh8VR'></tfoot><dl id='uh8VR'><fieldset id='uh8VR'></fieldset></dl></div>
                  <tfoot id='uh8VR'></tfoot>
                  本文介绍了在文本框中单击即可选择点击的单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在 Windows Phone 7 应用程序中.我碰巧有许多 TextBox 堆叠在 ItemsControl 中,并且跨文本框进行选择的行为并不统一,即单击任何文本框中的任何单词都不会选择轻敲的词.首先单击以聚焦文本框,然后单击以实际选择单词;但是一旦文本框获得焦点,只需单击一下即可选择其中的任何单词,直到用户想要在另一个文本框中选择其他单词.有没有办法消除这种情况?可能是通过在 GotFocus 事件上引发假鼠标左键向下和向上事件?

                  In a Windows Phone 7 app. I happen to have many TextBoxs stacked in a ItemsControl and the behaviour across textboxes for selection is not uniform i.e. a single click on any word in any text box does not select the tapped word. First a click is consumed for focusing the text box and then another to actually select the word; but once the text box has focus, it's a single click to select any word within, until the user wants to select some other word in another textbox. Is there a way to neutralize this? May be by raising fake mouse left button down and up events on a GotFocus event?

                  我所做的是,在 LeftMouseButtonDown(和向上)事件中,我存储了事件 args.在 GotFocus 上,我尝试使用存储的 args 引发事件,但用于引发事件的事件处理程序 var 始终为空,因此引发事件不会发生.我是 C# 的新手,所以我不确定我离题了.

                  What I did was, on a LeftMouseButtonDown (and up) Event I stored the event args. On a GotFocus, I tried to raise an event with the stored args, but the event handler var used to raise the event always is null, hence raise event doesn't happen. I'm new to C# so I'm not sure where I'm digressing.

                  推荐答案

                  刚刚发现了一个巧妙的技巧!只需轻按一下 TextBox 控件,它就会获得焦点,并且在使用 TextBox 的 SelectionStart 属性的 GotFocus 例程上,可以获取其前面有插入符号的当前字符.有了这些数据,可以找到带有空格字符的左右边界,从而选择单词.

                  Just found a neat trick! On a single tap of a TextBox control it gets focus and on GotFocus routine using SelectionStart property of TextBox one can get the current character which has the caret just before it. With this data the left and right boundaries with space character can be found and thus the word selected.

                      private void textBox_GotFocus(object sender, RoutedEventArgs e)
                      {
                          TextBox txtBox = (TextBox)sender;
                          char [] strDataAsChars = txtBox.Text.ToCharArray();
                          int i = 0;
                          for (i = txtBox.SelectionStart - 1; ((i >= 0) &&
                                             (strDataAsChars[i] != ' ')); --i) ;
                          int selBegin = i + 1;
                          for (i = txtBox.SelectionStart; ((i < strDataAsChars.Length) &&
                                                            (strDataAsChars[i] != ' ')); ++i) ;
                          int selEnd = i;
                          txtBox.Select(selBegin, selEnd - selBegin);
                      }
                  

                  把它贴在这里,以便以后可以帮助别人.

                  Posted it here so that it may help someone later on.

                  这篇关于在文本框中单击即可选择点击的单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:asp.net 验证文本框 - 至少一个文本框必须有数据 下一篇:文本框被一个巨大的字符串禁用

                  相关文章

                    <tfoot id='p4G5L'></tfoot>

                      • <bdo id='p4G5L'></bdo><ul id='p4G5L'></ul>
                    1. <small id='p4G5L'></small><noframes id='p4G5L'>

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

                      <legend id='p4G5L'><style id='p4G5L'><dir id='p4G5L'><q id='p4G5L'></q></dir></style></legend>