Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
523 views
in Technique[技术] by (71.8m points)

c# - Custom Caret for WinForms TextBox

I'm developing a custom HyperTerminal like application in a WinForms .Net 2.0 application. I have a multiline TextBox in a Panel in which you can interact with a hardware device.

My customer wants to have a custom Caret, a filled rectangle the size of one character space instead of the vertical line that is by default.

I know .Net does not provide an option to do this by default, but there must some Windows function to do it.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

These are the list of Native Caret functions provided by Windows you can use them for you application.

    [DllImport("User32.dll")]
    static extern bool CreateCaret(IntPtr hWnd, int hBitmap, int nWidth, int nHeight);

    [DllImport("User32.dll")]
    static extern bool SetCaretPos(int x, int y);

    [DllImport("User32.dll")]
    static extern bool DestroyCaret();

    [DllImport("User32.dll")]
    static extern bool ShowCaret(IntPtr hWnd);

    [DllImport("User32.dll")]
    static extern bool HideCaret(IntPtr hWnd);

Refer SharpDevelop, Source Code @ srcLibrariesICSharpCode.TextEditorProjectSrcGuiCaret.cs


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...