Click to See Complete Forum and Search --> : getting caret
stuckhere90
July 22nd, 2005, 08:51 PM
Hi All,
I am a C++ programmer moving to C#. In C++ we can get a caret (not to be confused with the cursor) if we want to. Is it possible to get a caret in C#. I am using it for a text editing program. Any suggestions welcome.
Thnaks.
jmcilhinney
July 23rd, 2005, 05:53 AM
When you say caret I assume you mean the insertion point in a TextBox or the like, as opposed to the mouse cursor. Have a look at the TextBoxBase.SelectionStart property.
stuckhere80
July 23rd, 2005, 04:42 PM
I am not using a text box at all, nor can I use one. Here is what I would like. The user moves the mouse in the client area of a form. If the user left clicks, then I place the caret there (ideally the caret would be blinking, like in Word) I can do a caret in C++. One would thing C# can to. If it can't, that is a significant drawback for people writing text stuff.
SouthernCodeMonkey
July 23rd, 2005, 06:40 PM
Greetings.
You will find the following win32 functions helpful:
namespace Example
{
public sealed class NativeFunctions
{
private NativeFunctions(){}
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("user32.dll")]
internal static extern int CreateCarat(IntPtr hWnd, IntPtr hBitmap, int Width, int Height);
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("user32.dll")]
internal static extern int GetCaratBlinkTime();
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("user32.dll")]
internal static extern int HideCarat(IntPtr hWnd);
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("user32.dll")]
internal static extern int SetCaretBlinkTime(int Milliseconds);
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("user32.dll")]
internal static int ShowCarat(IntPtr hWnd);
}
}
This isn't portable, but it works.
Regards.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.