如何在TextBox文字上设置光标? [英] How do i set cursor on TextBox text?

查看:250
本文介绍了如何在TextBox文字上设置光标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在TextBox文本上设置光标?

我想在用户将鼠标悬停在TextBox文本上时使用不同类型的光标指针吗?
在CSS中,我确实设置了cursor:pointer,然后当我用鼠标显示它时便显示了方便的光标
在TextBox上,但是我只想在输入的Text上显示它,所以
我该怎么做?

How do i set cursor on TextBox text?

i want the diffrent type of cursor pointer when user mouse over on TextBox text?
in css i did set the cursor:pointer then it shows the handy cursor when i mouse
over the TextBox, but i want to show that on entered Text only, so
how can i do that?

推荐答案

我不认为你可以,这就是为什么:

TextBox实际上是一个input元素,不包含内部HTML.其文本由属性Value表示. CSS仅在HTML元素级别起作用.这样,归因于输入的任何内容都将具有相同的样式.

我还认为您不需要它;这就是为什么:

不同的光标不仅用于装饰(对不起,如果您只想装饰,客户可能会不满意),视觉反馈的目的是:我可以在其中键入文本的光标.是的?单击并键入;如果您在元素内单击,则无论文本在哪里,它都将起作用.

—SA
I don''t think you can, here is why:

The TextBox is actually one input Element, not containing inner HTML. Its text is represented by the attribute Value. CSS only works at the level of HTML Elements. In this way, whatever is attributed to the input will be of the same style.

I also think you don''t need it; here is why:

The different cursor is not just for decoration (sorry for you if you want just decoration; you customers may not appreciate that), the purpose if the visual feedback: is the cursor where I can type the text. Yes? Click and type; it will work if you clicked inside the element, no matter where the text is.

—SA


我能够这样更改光标:

I was able to change the cursor like this :

private void textBox1_TextChanged(object sender, TextChangedEventArgs e)
{
    if (!String.IsNullOrEmpty(textBox1.Text))
    {
        textBox1.Cursor = Cursors.Hand;
    }
    else
    {
        textBox1.Cursor = Cursors.Arrow;
    }
}



对您有用吗?



Is it working for you?


这篇关于如何在TextBox文字上设置光标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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