简体   繁体   English

.NET CompactFramework TextBox.selectAll在gotFocus上

[英].NET CompactFramework TextBox.selectAll on gotFocus

i'm developing an application for an mobile device with WM 6.5 (.NET 3.5) and have the following problem: 我正在为具有WM 6.5(.NET 3.5)的移动设备开发应用程序,并且遇到以下问题:

When the textBox.gotFocus() event is called on an textBox in my form, I call the SelectAll() method of this textBox for selecting the entire text. 在窗体中的textBox上调用textBox.gotFocus()事件时,我将调用此textBox的SelectAll()方法来选择整个文本。

This method works in case of Tab navigation (selectNextControl()), but not in case of "touching" this textBox on device display. 如果使用Tab导航(selectNextControl()),则此方法有效,但如果“触摸”设备显示屏上的此textBox,则该方法无效。 In this case the selectAll() method is executed, but the text is not selected. 在这种情况下,将执行selectAll()方法,但不会选择文本。

Has anyone experience with this? 有人对此有经验吗? Thanks in advance 提前致谢

The problem is Windows Mobile's internal event handling. 问题是Windows Mobile的内部事件处理。 Using a timer and doing the SelectAll() a few milliseconds after the event is triggered fixes the problem. 使用计时器并在触发事件几毫秒后执行SelectAll()解决此问题。

Just do this instead of the usual SelectAll() in your GotFocus event handler: 只需在GotFocus事件处理程序中执行此操作即可,而不是通常的SelectAll()

var timer = new Timer { Interval = 100, Enabled = true };
timer.Tick += (EventHandler) delegate
{
    SelectAll();
    timer.Dispose();
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM