OVH Cloud OVH Cloud

Position du curseur

4 réponses
Avatar
J:o\)
Comment connaitre la position du curseur dans
un texte box ?

Merci & Have fun

J:o)

4 réponses

Avatar
LE TROLL
Heu, bonsoir, pour ma part, je ne vois pas, faudrait prendre un rtf,
là il me semble possible de pister le curseur (sous réserve, je dis ça de
tête)...
--------

"J:o)" a écrit dans le message de news:

Comment connaitre la position du curseur dans
un texte box ?

Merci & Have fun

J:o)





Avatar
J:o\)
Merci de ton aide !

Pour ma part, je n'ai toujours pas trouvé !

"LE TROLL" <le wrote in message
news:
Heu, bonsoir, pour ma part, je ne vois pas, faudrait prendre un
rtf,

là il me semble possible de pister le curseur (sous réserve, je dis ça de
tête)...
--------

"J:o)" a écrit dans le message de news:

Comment connaitre la position du curseur dans
un texte box ?

Merci & Have fun

J:o)









Avatar
Michel Pierron
Bonsoir J:o);
Un bouton Start
Un bouton Stop
Un checkBox (pixels ou points)
Un TextBox

Dans le module userform:
Option Explicit
Private Declare Function GetCursorPos _
Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Sub Sleep Lib "kernel32" _
(ByVal dwMilliseconds As Long)
Private Type POINTAPI
x As Long
y As Long
End Type
Private Cursor As Boolean

Private Sub CheckBox1_Click()
If CheckBox1 Then
CheckBox1.Caption = "Points"
Else
CheckBox1.Caption = "Pixels"
End If
End Sub

Private Sub CommandButton1_Click()
Me.Repaint
Cursor = True
Call Pointer
End Sub

Private Sub CommandButton2_Click()
Cursor = False
End Sub

Private Sub Pointer()
Dim PT As POINTAPI, R As String
While Cursor
GetCursorPos PT
If CheckBox1 Then
R = " (x:" & PT.x * 3 / 4 _
& " y:" & PT.y * 3 / 4 & ")"
Else
R = " (x:" & PT.x & " y:" & PT.y & ")"
End If
TextBox1.Text = CheckBox1.Caption & R
DoEvents
Sleep 100
Wend
TextBox1.Text = ""
End Sub

Ou bien dans la barre de status avec 2 boutons sur la feuille (pixels):
Dans un module standard:
Option Explicit
Private Declare Function GetCursorPos Lib "user32" _
(lpPoint As POINTAPI) As Long
Private Declare Sub Sleep Lib "kernel32" _
(ByVal dwMilliseconds As Long)
Private Type POINTAPI
x As Long
y As Long
End Type
Private Cursor As Boolean

Private Sub Pointer()
Dim PT As POINTAPI
While Cursor
GetCursorPos PT
Application.StatusBar = "Pointer (x:" & PT.x & " y:" & PT.y & ")"
DoEvents
Sleep 100
Wend
Application.StatusBar = False
End Sub

' Start
Sub Bouton1_QuandClic()
Cursor = True
Call Pointer
End Sub

' Stop
Sub Bouton2_QuandClic()
Cursor = False
End Sub

MP

"J:o)" a écrit dans le message de
news:
Comment connaitre la position du curseur dans
un texte box ?

Merci & Have fun

J:o)





Avatar
J:o\)
Bonsoir Michel,

Merci pour ta réponse très intéressante et
pour ton aide.

Cependant, je me suis mal exprimé !
Je cherche à connaitre la position du curseur
de saisie à l'intérieur d'un texte box et non
les coordonnées du pointeur de souris.

Merci encore

Jonathan

"Michel Pierron" wrote in message
news:#
Bonsoir J:o);
Un bouton Start
Un bouton Stop
Un checkBox (pixels ou points)
Un TextBox

Dans le module userform:
Option Explicit
Private Declare Function GetCursorPos _
Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Sub Sleep Lib "kernel32" _
(ByVal dwMilliseconds As Long)
Private Type POINTAPI
x As Long
y As Long
End Type
Private Cursor As Boolean

Private Sub CheckBox1_Click()
If CheckBox1 Then
CheckBox1.Caption = "Points"
Else
CheckBox1.Caption = "Pixels"
End If
End Sub

Private Sub CommandButton1_Click()
Me.Repaint
Cursor = True
Call Pointer
End Sub

Private Sub CommandButton2_Click()
Cursor = False
End Sub

Private Sub Pointer()
Dim PT As POINTAPI, R As String
While Cursor
GetCursorPos PT
If CheckBox1 Then
R = " (x:" & PT.x * 3 / 4 _
& " y:" & PT.y * 3 / 4 & ")"
Else
R = " (x:" & PT.x & " y:" & PT.y & ")"
End If
TextBox1.Text = CheckBox1.Caption & R
DoEvents
Sleep 100
Wend
TextBox1.Text = ""
End Sub

Ou bien dans la barre de status avec 2 boutons sur la feuille (pixels):
Dans un module standard:
Option Explicit
Private Declare Function GetCursorPos Lib "user32" _
(lpPoint As POINTAPI) As Long
Private Declare Sub Sleep Lib "kernel32" _
(ByVal dwMilliseconds As Long)
Private Type POINTAPI
x As Long
y As Long
End Type
Private Cursor As Boolean

Private Sub Pointer()
Dim PT As POINTAPI
While Cursor
GetCursorPos PT
Application.StatusBar = "Pointer (x:" & PT.x & " y:" & PT.y & ")"
DoEvents
Sleep 100
Wend
Application.StatusBar = False
End Sub

' Start
Sub Bouton1_QuandClic()
Cursor = True
Call Pointer
End Sub

' Stop
Sub Bouton2_QuandClic()
Cursor = False
End Sub

MP

"J:o)" a écrit dans le message de
news:
Comment connaitre la position du curseur dans
un texte box ?

Merci & Have fun

J:o)