TextBox选择不当 [英] TextBox selection improper

查看:66
本文介绍了TextBox选择不当的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

在TextBox中,我将文本设置为"21-01-1992"。当我双击文本"01"时,只有文字"01"。已选中。

In TextBox, I have set the text as "21-01-1992" When I double click on the text "01" only the text "01" is selected.

但是,如果我将文本设置为"21 // 01/1992"双击文本"01" TextBox中的整个文本被选中。我可以只选择文字"01"吗?以上述格式。

But, If I set the text as "21//01/1992" on double click on the text "01" The whole text in the TextBox gets selected. Can I select only the text "01" in this format as like above.

问候,

Senthil

R.Senthil

R.Senthil

推荐答案

您好Kumaran619,

Hi Kumaran619,

为此你首先得到光标位置,然后选择长度,请参考下面的代码:

For this purpose you should get the cursor position first, then select length, please refer to the below code:

        private void textBox2_DoubleClick(object sender, EventArgs e)
        {
            int a = this.textBox2.GetCharIndexFromPosition(this.textBox2.PointToClient(Cursor.Position));//get cursor
            textBox2.Select(a-1, 2);//cursor-1(start position) select-length
        }




您可以使用此方法自定义任何位置和长度。


You can customize any position and length from this method.

希望这会有所帮助!

最诚挚的问候,

Stanly


这篇关于TextBox选择不当的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆