Results 1 to 7 of 7

Thread: Using vbKeyLButton

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2004
    Posts
    17

    Using vbKeyLButton

    Hello all...
    I have a multiline text box, where i donot want the user to be able to set the cursor position anywhere using the left mouse click..above the current line. I have tried using text box keydown and keypress, also Text1_MouseDown and check like this:

    If KeyCode = vbKeyLButton Then
    KeyCode = 0
    End If

    but still nothing seems to work..can anuybody help me...
    thanls

  2. #2
    Addicted Member Psychotic's Avatar
    Join Date
    May 2004
    Posts
    164

    Re: Using vbKeyLButton

    in mousedown procedure...

    if button = vbleftbutton then 'do stuff
    -Psychotic-

  3. #3
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Using vbKeyLButton

    This will not allow the text cursor to be moved using the mouse.
    VB Code:
    1. Private Declare Function ReleaseCapture _
    2.  Lib "user32.dll" () As Long
    3.  
    4. Private nLastSel As Long
    5.  
    6. Private Sub Text1_Change()
    7.     nLastSel = Text1.SelStart
    8. End Sub
    9.  
    10. Private Sub Text1_GotFocus()
    11.     nLastSel = Text1.SelStart
    12. End Sub
    13.  
    14. Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
    15.     Select Case KeyCode
    16.         Case vbKeyDown, vbKeyUp, vbKeyLeft, vbKeyRight, vbKeyHome, vbKeyEnd
    17.             MsgBox "h"
    18.             nLastSel = Text1.SelStart
    19.     End Select
    20. End Sub
    21.  
    22. Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    23.     If Button = vbLeftButton Then
    24.         ReleaseCapture
    25.     End If
    26. End Sub
    EDIT: Forgot about the arrow keys. Fixed that!
    Last edited by Joacim Andersson; Jun 17th, 2005 at 11:49 PM.

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Apr 2004
    Posts
    17

    Re: Using vbKeyLButton

    hello joacim,

    iam still able to move the cursor using the left mouse button using the code that u wrote..releasecapture api is probably not doing anything...do uahve any suggestions..thanks

  5. #5
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Using vbKeyLButton

    Sorry, I forgot the most important part, to reset the text caret. LOL, that whats happens when you write the code directly into the post instead of testing it first. Change the MouseDown code to this:
    VB Code:
    1. Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    2.     If Button = vbLeftButton Then
    3.         ReleaseCapture
    4. [b]        Text1.SelStart = nLastSel [/b]
    5.     End If
    6. End Sub

  6. #6
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Using vbKeyLButton

    Quote Originally Posted by Apollyon255
    is there anybody here know what is the ascii keyboard value of Function Keys such as F1 tru F12???... i try it to kypress event but it doesn't return any value..
    First of all, it's considered very unpolite to hog someone elses thread and ask a new question. You should start a new thread instead .

    However, the function keys doesn't have any Ascii values. But you can still trap them using the keyboard scan code. This is done in VB using the KeyDown event instead of the KeyPress event.
    VB Code:
    1. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    2.     If KeyCode = vbKeyF1 Then
    3.         MsgBox "F1 was pressed"
    4.     End If
    5. End Sub
    The named constants for the function keys are vbKeyF1 to vbKeyF12. If you want to try out this code make sure you set the KeyPreview property of the Form to True.

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Apr 2004
    Posts
    17

    Re: Using vbKeyLButton

    thanks so much joacim, it worked....

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