|
-
Jun 17th, 2005, 10:53 PM
#1
Thread Starter
Junior Member
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
-
Jun 17th, 2005, 10:58 PM
#2
Addicted Member
Re: Using vbKeyLButton
in mousedown procedure...
if button = vbleftbutton then 'do stuff
-
Jun 17th, 2005, 11:40 PM
#3
Re: Using vbKeyLButton
This will not allow the text cursor to be moved using the mouse.
VB Code:
Private Declare Function ReleaseCapture _
Lib "user32.dll" () As Long
Private nLastSel As Long
Private Sub Text1_Change()
nLastSel = Text1.SelStart
End Sub
Private Sub Text1_GotFocus()
nLastSel = Text1.SelStart
End Sub
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyDown, vbKeyUp, vbKeyLeft, vbKeyRight, vbKeyHome, vbKeyEnd
MsgBox "h"
nLastSel = Text1.SelStart
End Select
End Sub
Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
ReleaseCapture
End If
End Sub
EDIT: Forgot about the arrow keys. Fixed that!
Last edited by Joacim Andersson; Jun 17th, 2005 at 11:49 PM.
-
Jun 18th, 2005, 10:18 AM
#4
Thread Starter
Junior Member
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
-
Jun 18th, 2005, 10:30 AM
#5
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:
Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
ReleaseCapture
[b] Text1.SelStart = nLastSel [/b]
End If
End Sub
-
Jun 18th, 2005, 10:37 AM
#6
Re: Using vbKeyLButton
 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:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyF1 Then
MsgBox "F1 was pressed"
End If
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.
-
Jun 18th, 2005, 03:23 PM
#7
Thread Starter
Junior Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|