How to show cursor in unfocused WinForms TextBox/RichTextBox?

我的未来我决定 提交于 2019-12-01 08:40:50

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

You can't set focus to the two or more UI at same time however you can preserve the selection by setting HideSelection=false.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!