Re: Caret in TextBox

From: Paul (paulp_at_online.nospam)
Date: 07/15/04


Date: Thu, 15 Jul 2004 08:47:03 -0700

I have now found how to suppress the caret by 'importing' Win32 as follows:

/// <summary>
/// The HideCaret function removes the caret from the screen.
/// </summary>
[DllImport("user32.dll")]
private static extern bool HideCaret(IntPtr hWnd);

and then invoke it as follows:

HideCaret(mainRichTextBox.Handle);

for:

private System.Windows.Forms.RichTextBox mainRichTextBox;

Only problem is that the caret re-appears when the mouse is clicked anywhere in the client area! Hopefully, I will find a way round this one too.

Thanks once again,

Paul

"Herfried K. Wagner [MVP]" wrote:

> * "=?Utf-8?B?UGF1bA==?=" <paulp@online.nospam> scripsit:
> > I am trying to use a 'read-only' TextBox control in c# to display text with the possibility of scrolling it horizontally and vertically. However, I cannot find any easy way of suppressing (making invisible) the caret.
> >
> > The only way of achieving this that I can see is to somehow get a window handle to the control and to then use the HideCaret API call.
> >
> > Is there any easier way? If not, how do I get a handle to the TextBox control?
>
> Add a label control to a panel control with 'AutoScroll' set to 'True'.
>
> --
> Herfried K. Wagner [MVP]
> <URL:http://dotnet.mvps.org/>
>



Relevant Pages

  • RE: Caret Position in Textbox Control
    ... index of the caret in a TextBox control. ... Microsoft Online Community Support ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.dotnet.framework.windowsforms.controls)
  • Re: type directly on graphic object: caret ?
    ... TextBox control, I think you'll find that the caret stuff is still ... Search for .Net wrappers for the following Win32 API functions: ... not be much problem with GDI+, using measurestring or char. ...
    (microsoft.public.dotnet.framework.drawing)