CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: getting caret

  1. #1
    Join Date
    Jun 2005
    Posts
    5

    getting caret

    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.

  2. #2
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    1,080

    Re: getting caret

    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.

  3. #3
    Join Date
    Jun 2002
    Posts
    58

    Re: getting caret

    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.

  4. #4
    Join Date
    Feb 2005
    Posts
    106

    Re: getting caret

    Greetings.

    You will find the following win32 functions helpful:

    Code:
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured