Keep a TextBox from displaying its caret (cursor)?

  • Thread starter Thread starter Michael A. Covington
  • Start date Start date
M

Michael A. Covington

How do you keep a TextBox from displaying its caret (blinking vertical line,
insertion point)?

Setting it to ReadOnly doesn't do the job in VS 2005.
 
If the user isn't allowed to enter text in the TextBox you could use the
label control as an alternative.

Ole
 
The below will do it..

[DllImport("user32")] private static extern bool HideCaret(IntPtr hWnd);

public void HideCaret()
{
HideCaret(TextBox1.Handle);
}
 
VJ said:
The below will do it..

[DllImport("user32")] private static extern bool HideCaret(IntPtr hWnd);

public void HideCaret()
{
HideCaret(TextBox1.Handle);
}

Thanks, but as far as I can tell, this has no effect. When should it be
done? Immediately after AppendText?
 
Ole said:
If the user isn't allowed to enter text in the TextBox you could use the
label control as an alternative.

It needs to be multiline. My impression was that labels are always only 1
line.

But thanks.
 
Michael.. I have done the below in text changed as well as lost foucs, never
had any issues. Is there a sample code you can give that has the problem?

Michael A. Covington said:
VJ said:
The below will do it..

[DllImport("user32")] private static extern bool HideCaret(IntPtr hWnd);

public void HideCaret()
{
HideCaret(TextBox1.Handle);
}

Thanks, but as far as I can tell, this has no effect. When should it be
done? Immediately after AppendText?
 
Sorry about that, this should not be done in lost focus. Yes I have done in
text changed it has worked, just checked out and it worked

VJ

VJ said:
Michael.. I have done the below in text changed as well as lost foucs,
never had any issues. Is there a sample code you can give that has the
problem?

Michael A. Covington said:
VJ said:
The below will do it..

[DllImport("user32")] private static extern bool HideCaret(IntPtr hWnd);

public void HideCaret()
{
HideCaret(TextBox1.Handle);
}

Thanks, but as far as I can tell, this has no effect. When should it be
done? Immediately after AppendText?
 
I'll try doing it in the TextChanged event. Thanks.

VJ said:
Sorry about that, this should not be done in lost focus. Yes I have done
in text changed it has worked, just checked out and it worked

VJ

VJ said:
Michael.. I have done the below in text changed as well as lost foucs,
never had any issues. Is there a sample code you can give that has the
problem?

Michael A. Covington said:
The below will do it..

[DllImport("user32")] private static extern bool HideCaret(IntPtr
hWnd);

public void HideCaret()
{
HideCaret(TextBox1.Handle);
}


Thanks, but as far as I can tell, this has no effect. When should it be
done? Immediately after AppendText?
 
There is no problem in writing multiple lines in a label.

try this (create a form with a label on):
public Form1()
{
InitializeComponent();
label1.Text = "This label has two" + Environment.NewLine + "lines, and
could be more";
}

Ole
 
Back
Top