I need to show cursor in RichTextBox control in WinForms application even when it's not in focus. How can I do this? I found only the way for WPF ( How to keep WPF TextBox selection when not focused?)
Asked
Active
Viewed 3,224 times
4
-
I actually do not know the solution, but if there isnt any, then i would explicitely write | and erase and again write in an interval into that RTBox. Upon getting its focus or clicking that component i shall start this timer or similar thing to stop doing this operation. I know its crude and improper way, thats all i got so far on top of my head :) – Zenwalker Oct 24 '11 at 09:30
-
1I don't think it's a good idea, because that would be confusing! Why would you do anything like that? And no I don't think it possible. – Sai Kalyan Kumar Akshinthala Oct 24 '11 at 09:32
-
For app like Transcriber http://trans.sourceforge.net/en/presentation.php it shows both sound and text editor – Singlet Oct 24 '11 at 09:42
3 Answers
2
You can use WinAPI ..
[DllImport("user32.dll", EntryPoint = "ShowCaret")]
public static extern long ShowCaret(IntPtr hwnd);
[DllImport("user32.dll", EntryPoint = "HideCaret")]
public static extern long HideCaret(IntPtr hwnd);
and call ShowCaret whenever you want

Mohamed Abed
- 5,025
- 22
- 31
-
From Windows Api reference "A window should create a caret only when it has the keyboard focus or is active.The window should destroy the caret before losing the keyboard focus or becoming inactive." So it's not possible to implement this feature with standard controls without own cursor handling? – Singlet Oct 24 '11 at 11:41
1
You can't set focus to the two or more UI at same time however you can preserve the selection by setting HideSelection=false
.

KV Prajapati
- 93,659
- 19
- 148
- 186
-
It's don't work - when HideSelection= false only selection is showing, but no blinking cursor. – Singlet Oct 24 '11 at 09:37
-
This property keeps selected text when control looses focus, but not cursor. – Renatas M. Oct 24 '11 at 09:38
-
@Reniuz - Read my post - "You can't set focus to the two or more UI at same time" – KV Prajapati Oct 24 '11 at 09:40
0
I don't know what you are trying to achieve and how much is it really useful. But if it is just for visual purpose, write some thing like '|' in it. Its a bad, weird, awkward way or what ever you call it, for visual purpose it may work.
public void blink()
{
while (true)
{
textBox1.Text = "|";
Thread.Sleep(200);
textBox1.Text = "";
Thread.Sleep(200);
}
}
private void Form1_Load(object sender, EventArgs e)
{
Thread t1 = new Thread(new ThreadStart(blink));
t1.Start();
}
I am not sure if I am giving is what you are asking, but to get accurate answer, you have to expose your need of this requirement.
Hope it helps.

Sandy
- 11,332
- 27
- 76
- 122