Windows mobile 如何以编程方式选择TextBox控件的所有文本(Compact.NET 2.0)

Windows mobile 如何以编程方式选择TextBox控件的所有文本(Compact.NET 2.0),windows-mobile,windows-ce,Windows Mobile,Windows Ce,我想在GotFocus事件中选择System.Windows.Forms.TextBox()控件的所有文本,但我找到的所有示例都使用了该控件的.SelectionStart/.SelectionEnd属性,而这些属性在.NET 2.0 Framework中不可用 using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data;

我想在GotFocus事件中选择System.Windows.Forms.TextBox()控件的所有文本,但我找到的所有示例都使用了该控件的.SelectionStart/.SelectionEnd属性,而这些属性在.NET 2.0 Framework中不可用

using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace xCustomControls
{
    public partial class xTextBox : System.Windows.Forms.TextBox
    {
        public xTextBox()
        {
            InitializeComponent();
            this.GotFocus += new System.EventHandler(this.GotFocusHandler);
        }

        private void GotFocusHandler(object sender, EventArgs e)
        {
            Control ctrl = (Control)sender;
            ctrl.BackColor = Color.Cyan;
            ctrl.SelectionStart = 0;
        }
错误:

“System.Windows.Forms.Control”不包含“SelectionStart”的定义,并且找不到接受“System.Windows.Forms.Control”类型的第一个参数的扩展方法“SelectionStart”(是否缺少using指令或程序集引用?)

有什么想法吗

蒂亚, 巴勃罗

更换线路

Control ctrl = (Control)sender;

编译器认为您使用的是一个控件类,它没有SelectionStart,但您的对象实际上是的派生,它有

TextBox ctrl = (TextBox)sender;