Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
692to696
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
692to696
692to696
Aktuelles Verzeichnis
Verzeichnis Index
Verzeichnis Index
Übersicht Verzeichnisse
Inhaltsverzeichnis

Mausposition im Form Designer

Mausposition im Form Designer
14.11.2005 09:20:44
Hans
Hallo an alle,
wie kann ich im Form Designer, die Cursorposition angeben mit den x und y Koordinaten. Er zeigt mir schon die x und y Koordinaten an, aber mein Problem ist das ich Labels, Textbox, Checkbox und ComboBox in meinem Form Designer habe. Wenn ich ausserhalb dieser Labels bin zeigt er mir die Koorinaten von der Maus an, aber sobald ich in den Labels, Textbox, Etc. drin bin zeigt er mir die Koordinaten der jeweiligen Felder. Ich möchte, dass er mir auch in den Feldern die Cursor Koordinaten liefert. Wie mache ich das?
Gruss Hans

2
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Mausposition im Form Designer
14.11.2005 16:31:15
Leo
Hi,
Beispiel für eine Textbox(nur X):

Private Sub TextBox1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Me.Caption = TextBox1.Left + X
End Sub


Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Me.Caption = X
End Sub

mfg Leo
AW: Mausposition im Form Designer
14.11.2005 20:09:49
Nepumuk
Hallo Hans,
noch nicht weiter gekommen? Ist doch ganz einfach:
' **********************************************************************
' Modul: Modul1 Typ: Allgemeines Modul
' **********************************************************************

Option Explicit
Option Private Module

Private Declare Function GetCursorPos Lib "user32" ( _
    lpPoint As POINTAPI) As Long

Private Type POINTAPI
    x As Long
    y As Long
End Type

Public Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type

Public udtRect As RECT
Private udtPoint As POINTAPI

Public Sub prcTimer(ByVal hwnd As Long, ByVal nIDEvent As Long, _
        ByVal uElapse As Long, ByVal lpTimerFunc As Long)

    On Error Resume Next
    GetCursorPos udtPoint
    If udtPoint.y >= udtRect.Top And udtPoint.y <= udtRect.Bottom And _
        udtPoint.x >= udtRect.Left And udtPoint.x <= udtRect.Right Then
        UserForm1.Label1.Caption = "x: " & CStr(udtPoint.x - udtRect.Left) & _
            " y: " & CStr(udtPoint.y - udtRect.Top)
    Else
        UserForm1.Label1.Caption = "Outside"
    End If
End Sub

Public Sub prcStart()
    UserForm1.Show
End Sub

' **********************************************************************
' Modul: UserForm1 Typ: Userform
' **********************************************************************

Option Explicit

Private Declare Function KillTimer Lib "user32" ( _
    ByVal hwnd As Long, _
    ByVal nIDEvent As Long) As Long
Private Declare Function SetTimer Lib "user32" ( _
    ByVal hwnd As Long, _
    ByVal nIDEvent As Long, _
    ByVal uElapse As Long, _
    ByVal lpTimerFunc As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
    ByVal lpClassName As String, _
    ByVal lpWindowName As String) As Long
Private Declare Function GetWindowRect Lib "user32" ( _
    ByVal hwnd As Long, _
    lpRect As RECT) As Long

Private Const gcClassnameMSExcelForm = "ThunderDFrame"

Private hwnd As Long

Private Sub UserForm_Activate()
    hwnd = FindWindow(gcClassnameMSExcelForm, Me.Caption)
    GetWindowRect hwnd, udtRect
    udtRect.Top = udtRect.Top + 21 '21 = Höhe der Titelleiste
    SetTimer hwnd, 0, 10, AddressOf prcTimer
End Sub

Private Sub UserForm_Terminate()
    KillTimer hwnd, 0
End Sub

Gemessen wird in Pixel. Um das in Points, welche im Userform als Maßeinheit verwendet wird, umzurechnen, musst du mit 0,75 multiplizieren.
Hier mal das ganze eingebaut in eine Beispielmappe:
https://www.herber.de/bbs/user/28388.xls
Gruß
Nepumuk

Anzeige

Links zu Excel-Dialogen

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige