防止文本框中的光标闪烁 [英] Prevent Blinking Cursor in Textbox
问题描述
在文本框中,如何防止单击时显示闪烁的光标?
In a textbox, how can u prevent the display of the blinking cursor when you click on it?
我确实在一些论坛中读到有一个调用特定的api,但是当我在代码中尝试使用api时,显示错误。请提供为此目的的完整代码,并让我知道是否在某个特定事件中应执行该代码。
I did read in some forums that there is call to a particular api but when i tried it in my code, an error was shown. Please provide the complete code for this purpose if possible and let me know if there is a particular event where the code should be executed.
此文本框是表单窗口的一部分是为模拟局域网通讯程序而创建的。我正在使用C#。表单具有两个文本框,以类似于google talk的文本框。希望防止在上方的文本框中显示闪烁的光标。
This textbox is part of a form window that am creating for the simulation of a lan messenger. I am using C#. The form has two textboxes in order to resemble that of google talk. It would be desirable to prevent displaying the blinking cursor on the upper textbox.
我尝试过:
[DllImport("user32")]
private static extern bool HideCaret(IntPtr hWnd);
public void HideCaret() { HideCaret(TextBox1.Handle); }
我收到错误消息:找不到DllImport。
I get the error: "DllImport could not be found."
推荐答案
如果要禁止在文本框中进行编辑,请将其ReadOnly属性设置为true。
If you want to disallow editing on the textbox, set it's ReadOnly property to true.
如果要允许编辑但仍隐藏插入记号,请完全按指定的方式调用Win32 API :
If you want to allow editing but still hide the caret, call the Win32 API exactly as specified:
[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern bool HideCaret(IntPtr hWnd);
...
HideCaret(myTextBox.Handle);
这篇关于防止文本框中的光标闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!