Results 1 to 16 of 16

Thread: vbexpress2010 how to disable I beam cursor inside textbox? (notmousecursor)

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2011
    Posts
    268

    vbexpress2010 how to disable I beam cursor inside textbox? (notmousecursor)

    Hey, yeah i wanna make a proper system to hide the I beam cursor in a textbox,
    you know, when you click on a textbox, the cursor appears so u can know where to write, etc... i want it disabled, is there such thing possible with a code? or do i really have to play around with focus? i hate playing around with object focus :P

  2. #2
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: vbexpress2010 how to disable I beam cursor inside textbox? (notmousecursor)

    What is the purpose of disable the ibeam, cos you dont like the look of it/the selection or you want to stop the user doing something?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2011
    Posts
    268

    Re: vbexpress2010 how to disable I beam cursor inside textbox? (notmousecursor)

    i dont want the look of it, i want the user to still be able to select text if he wants to, but the I beam on a readonly textbox is kinda missleading if u know what i mean

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: vbexpress2010 how to disable I beam cursor inside textbox? (notmousecursor)

    Not really... since the user will still be able to select text, the i-beam is appropriate...If I went to go select text in a textbox and my cursor disappeared... how would I know where to select... or what I'm selecting. Just because YOU don't like it, isn't a valid reason... if the USER asked for it, I'd talk them out of it... but still, don't enforce your OPINIONS on your users like that.You're asking to change standard windows functionality... generally not a good idea as it just confuses users.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2011
    Posts
    268

    Re: vbexpress2010 how to disable I beam cursor inside textbox? (notmousecursor)

    imagine it like this, hightlight a post message with your mouse cursor, you see how the toggling | or I or whatever u wanna call it cursor doesnt appear? now if u create a message, the I or | cursor appears on that message box because you can write in there, but you obviously cannot write theards and posts made by other users, the toggling cursor is hidden, i want that effect, is it possible or not?
    PS: having a read only textbox with a toggling cursor as if t was a notepad is more confusing if you ask me.
    Thanks in advance!

  6. #6
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: vbexpress2010 how to disable I beam cursor inside textbox? (notmousecursor)

    Quote Originally Posted by Legendary_Agent View Post
    imagine it like this, hightlight a post message with your mouse cursor, you see how the toggling | or I or whatever u wanna call it cursor doesnt appear? now if u create a message, the I or | cursor appears on that message box because you can write in there, but you obviously cannot write theards and posts made by other users, the toggling cursor is hidden, i want that effect, is it possible or not?
    PS: having a read only textbox with a toggling cursor as if t was a notepad is more confusing if you ask me.
    Thanks in advance!
    That is called the Caret, read up on HideCaret..,
    http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx
    http://www.pinvoke.net/default.aspx/...HideCaret.html

    To hide the caret should be something simple like....
    Code:
    Imports System.Runtime.InteropServices
    
    Public Class Form1
    
        <DllImport("user32")> _
        Private Shared Function HideCaret(ByVal hWnd As IntPtr) As Integer
        End Function
    
        Private Sub TextBox1_GotFocus(sender As Object, e As System.EventArgs) Handles TextBox1.GotFocus
    	HideCaret(TextBox1.Handle)        
        End Sub
    
    End Class

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2011
    Posts
    268

    Re: vbexpress2010 how to disable I beam cursor inside textbox? (notmousecursor)

    hey im sorry, i dont know how to get it to work, could you please tell me where i should put that code?
    Thanks in advance!

    And 1 last important thing i need, probably this one is easy, sometimes i use my textboxes as some file icons, its hard to explain, basically the user can click the textboxes and the program does something...

    Is there any way i can change the cursor properly? i tried it like this:


    private sub richtextbox1_mousemove(byval sender as object, byval e as.system.eventargs) handles richtextbox1.mousemove
    cursor.current = cursors.arrow
    end sub


    in windows xp this code semms to work fine but in windows vista, everytime i move around the cursor on the richtextbox the cursor changes shape back to ibeam and then back to hand and back to ibeam again and back to hand again, this is happening in a matter of milliseconds, so you get a weird effect.... is there a way around this?

  8. #8
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: vbexpress2010 how to disable I beam cursor inside textbox? (notmousecursor)

    Quote Originally Posted by Legendary_Agent View Post
    hey im sorry, i dont know how to get it to work, could you please tell me where i should put that code?
    Not sure what else there is to show, do some research?

    Is there any way i can change the cursor properly? i tried it like this:

    private sub richtextbox1_mousemove(byval sender as object, byval e as.system.eventargs) handles richtextbox1.mousemove
    cursor.current = cursors.arrow
    end sub
    I don't understand why you would be changing the cursor in the mouse move event, I just set the controls cursor in the IDE or in code as needed, it shouldn't change unless you tell it to.

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2011
    Posts
    268

    Re: vbexpress2010 how to disable I beam cursor inside textbox? (notmousecursor)

    i have fixed the cursor code now, i wasnt aware that you could set the cursor icon independently for each control in the form, however i still need to find a way to hide the caret inside a read only textbox, could anyone please help me with that its so annoying

  10. #10
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: vbexpress2010 how to disable I beam cursor inside textbox? (notmousecursor)

    Why bother? w/o a caret, the use can't select the data... just use a label. You're trying to change how Windows works by default naturally. You're just going to confuse people.

    But hey hey whatever.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  11. #11
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: vbexpress2010 how to disable I beam cursor inside textbox? (notmousecursor)

    Quote Originally Posted by Legendary_Agent View Post
    i have fixed the cursor code now, i wasnt aware that you could set the cursor icon independently for each control in the form, however i still need to find a way to hide the caret inside a read only textbox, could anyone please help me with that its so annoying
    The code I posted above hides the blinking Caret in a textbox (tested in WinXP only) and has nothing to do with the cursor.

    If you want to hide the cursor too I'm sure there is a way, only thing that comes to mind is to use a (empty/blank) custom cursor which I haven't done in .Net, in VB6 there is a custom setting which allowed you to load your own cursor image.

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2011
    Posts
    268

    Re: vbexpress2010 how to disable I beam cursor inside textbox? (notmousecursor)

    thanks edge meal but i tried to use it and i had errors, i pasted the :

    Code:
        <DllImport("user32")> _
        Private Shared Function HideCaret(ByVal hWnd As IntPtr) As Integer
        End Function
    
        Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.GotFocus
            HideCaret(RichTextBox2.Handle)
        End Sub      
        End Sub
    into Public Class


    and this is the error i have:

    Error 1 Type 'DllImport' is not defined
    Warning 2 Function 'HideCaret' doesn't return a value on all code paths. Are you missing a 'Return' statement?
    Error 3 Handles clause requires a WithEvents variable defined in the containing type or one of its base types.


    And no i dont want to hide the cursor, just hide the caret, and im sorry for beying a newb with that code, i havent messed with functions at all nor with dll :\

  13. #13
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: vbexpress2010 how to disable I beam cursor inside textbox? (notmousecursor)

    Quote Originally Posted by Legendary_Agent View Post
    thanks edge meal but i tried to use it and i had errors, i pasted the :
    You need to call the API in your controls GotFocus event, unless the richtextbox is called TextBox1 (which would be stupid) that would never work.

    If you double click on your RTB control, then in the upper-right dropdown box in the code window select GotFocus, this will create or put the cursor in the GotFocus sub for you, now you can add code for that event.

    Code:
    Private Sub RichTextBox2_GotFocus(sender As Object, e As System.EventArgs) Handles RichTextBox2.GotFocus
        HideCaret(RichTextBox2.Handle)
    End Sub
    In your original post you said textbox now you seem to have changed that to richtextbox.
    I've never tried that API on a RTB before but seems to be a bit more fussy, for example clicking inside the control with the mouse or scrolling it will make the blinking caret reappear, so it seems you'll need to find a better way to do what you want or call the HideCaret API in more events then just the controls GotFocus event if needed.

    Good luck!

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2011
    Posts
    268

    Re: vbexpress2010 how to disable I beam cursor inside textbox? (notmousecursor)

    hmmmmmmmmmmmm, i see, i cant understand why on earth didnt they make this as a programmable option inside vb language....

    yes i have richtextboxes too where i need this code, actually more on richtextboxes than on textboxes....
    its now like this:

    Code:
    Public Class Form1
        Structure cartas
            Dim numero As Integer
            Dim remetente As String
            Dim destinatario As String
            Dim mensagem As String
        End Structure
        Public mensagens(0) As cartas
        Dim leitor As System.IO.StreamReader
        <DllImport("user32")> _
        Private Shared Function HideCaret(ByVal hWnd As IntPtr) As Integer
        End Function
        Private Sub RichTextBox2_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles RichTextBox2.GotFocus
            HideCaret(RichTextBox2.Handle)
        End Sub
    And i still have 2 errors:
    Error 1 Type 'DllImport' is not defined
    Warning 2 Function 'HideCaret' doesn't return a value on all code paths. Are you missing a 'Return' statement?

  15. #15
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: vbexpress2010 how to disable I beam cursor inside textbox? (notmousecursor)

    Quote Originally Posted by Legendary_Agent View Post
    hmmmmmmmmmmmm, i see, i cant understand why on earth didnt they make this as a programmable option inside vb language....
    If they added everything to the framework it would just be more bloatware, they have to draw the line somewhere I guess.

    Did you add Runtime.InteropServices to the top of the class?

    If "<DllImport("user32")> _" has a blue squiggly line under it and ends in a red line, place your mouse cursor over the red line and click the red Error Correction Options button, you should now see the image I posted below, click first line (apply fix) and it will add Imports System.Runtime.InteropServices to the top of the class for you.
    Attached Images Attached Images  
    Last edited by Edgemeal; May 29th, 2011 at 03:07 PM.

  16. #16

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2011
    Posts
    268

    Re: vbexpress2010 how to disable I beam cursor inside textbox? (notmousecursor)

    thanks a tons mate now it works for textboxes, the only thing that remains is for me to find a way to make it work for richtextboxes aswell as atm its not working as you said it before.

    Rep added and thanks a tons for your extra patience with me xD

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