locked
How to hide Cursor in Compact Framework RRS feed

  • Question

  • Hi, i m using textbox, it is readonly in Compact Framework. Wen i click on the textbox, Cursor blinks there. I want that Cursor should not be displayed there. I m also using Cursor.Hide(). but its not working. Cursor is still showing. please guide me.
    Monday, December 1, 2008 3:48 PM

Answers

  •  NAJAFAHEER wrote:
    Hi, i m using textbox, it is readonly in Compact Framework. Wen i click on the textbox, Cursor blinks there. I want that Cursor should not be displayed there. I m also using Cursor.Hide(). but its not working. Cursor is still showing. please guide me.

     

    The “blinking cursor” in the text box (edit control) is generally called “caret” for distinction. To hide the caret you need to do two things:

     

     1. When the textbox gets focus, you hide the caret by P/Invoking the HideCaret function.

     2. When the textbox loses focus, you need to show the caret by P/Invoking the ShowCaret function.

    Wednesday, December 3, 2008 9:23 AM

All replies

  • Hi,

     

    What you could do is handle the Focus event and then change the focused control from the textbox :-

     

    Code Snippet

    this.textBox1.GotFocus += new EventHandler(textBox1_GotFocus);

    private void textBox1_GotFocus(object sender, EventArgs e)

    {

    this.Focus();

    }

     

     

    This will then prevent the text box from having the focus and therefore showing the cursor.

     

    Hope this helps.

     

    Paul Diston

     

    Monday, December 1, 2008 4:09 PM
  • Hi

    Actually Do need focus the control when you click that control.

    So you can achieve this in many ways.
    1. use the mouse click event and redirect to focus to your form or any other place
    2. use the key up event or and redirect to your focus to form.

    that's good idea.
    Tuesday, December 2, 2008 2:06 AM
  •  NAJAFAHEER wrote:
    Hi, i m using textbox, it is readonly in Compact Framework. Wen i click on the textbox, Cursor blinks there. I want that Cursor should not be displayed there. I m also using Cursor.Hide(). but its not working. Cursor is still showing. please guide me.

     

    The “blinking cursor” in the text box (edit control) is generally called “caret” for distinction. To hide the caret you need to do two things:

     

     1. When the textbox gets focus, you hide the caret by P/Invoking the HideCaret function.

     2. When the textbox loses focus, you need to show the caret by P/Invoking the ShowCaret function.

    Wednesday, December 3, 2008 9:23 AM
  • I cann't understand. Is P/Invoking is a .net function or  ??????????? if u have a piece of code then plz forward me it may be helpful for me in understanding.
    Wednesday, December 3, 2008 10:14 AM
  • P/Invoke is a mechanism for managed code (.NET) to use unmanaged code (functions in C/C++ DLLs). Here is an introduction that will help you understand it:
     An Introduction to P/Invoke and Marshaling  

     

    For code  samples of P/Invoking ShowCaret/HideCaret functions, you can search for them here:
     
    http://www.pinvoke.net/search.aspx?search=ShowCaret

     

    Thursday, December 4, 2008 3:07 AM