Thema Datum  Von Nutzer Rating
Antwort
13.04.2023 08:50:06 Julaka
Solved
13.04.2023 12:34:07 Ulrich
NotSolved
13.04.2023 13:32:28 Gast79500
NotSolved
13.04.2023 21:50:11 xlKing
NotSolved
19.04.2023 13:29:27 Gast79500
NotSolved
21.04.2023 21:21:12 xlKing
NotSolved
23.04.2023 13:37:50 Gast79500
NotSolved
24.04.2023 00:36:40 xlKing
NotSolved
25.04.2023 01:22:27 Gast79500
NotSolved
25.04.2023 19:09:57 xlKing
NotSolved
26.04.2023 16:23:30 sauber....;-)....
NotSolved
13.04.2023 22:36:52 volti
Solved
14.04.2023 11:39:22 Julaka
NotSolved
14.04.2023 11:50:10 volti
Solved
14.04.2023 14:29:39 Julaka
NotSolved
Blau ToolTipText
14.04.2023 17:59:56 volti
Solved
17.04.2023 11:24:58 Julaka
Solved
21.04.2023 08:01:45 Julaka
NotSolved
21.04.2023 09:20:28 volti
NotSolved

Ansicht des Beitrags:
Von:
volti
Datum:
14.04.2023 17:59:56
Views:
357
Rating: Antwort:
 Nein
Thema:
ToolTipText

Hallo,

anstatt mit Sleep,Ontime oder Tickercounts eine verzögerte Anzeige zu realisieren, habe ich mich für das unsichtbar-/ sichtbarschalten entschieden.

Hierbei wird die Tooltipbox zwar wie bisher sofort erstellt, aber erst nach Ablauf der gewünschten Zeit sichtbar geschaltet. Relativ einfach, ansonsten hätte ich das Konzept weitergehend umstellen müssen.

Probiere es halt mal aus.

PS: Im code u.a. auf miDelayCount achten.....

Code:
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
 
Option Explicit

Public oButton() As New clsCommandButton

Private Declare PtrSafe Function SetTimer Lib "user32" ( _
        ByVal hwnd As LongPtrByVal nIDEvent As LongPtr, _
        ByVal uElapse As LongByVal lpTimerFunc As LongPtrAs LongPtr
Private Declare PtrSafe Function KillTimer Lib "user32" ( _
        ByVal hwnd As LongPtrByVal nIDEvent As LongPtrAs Long
Private Declare PtrSafe Function GetCursorPos Lib "user32" ( _
        lpPoint As POINTAPIAs Long
Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Type POINTAPI
     X      As Long
     Y      As Long
End Type
Dim Pt     As POINTAPI

Private hTimer As LongPtr, oCurObj As Object

Dim msOldBtnText As String
Dim miDelayCount As Long

Private Const ciDelayTime As Long = 50       ' Hier eine Verzögerung einstellen

Sub Tooltip_Initiate(WSh As Worksheet)
' Einlesen der vorhandenen Buttons in das Button-Array
' Nur für die Klassenprogrammierung nötig
  Dim oOleObj As OLEObject, i As Integer

  For Each oOleObj In WSh.OLEObjects
      If TypeOf oOleObj.Object Is MSForms.CommandButton Then
         i = i + 1
         ReDim Preserve oButton(i)
         Set oButton(i).moCommandButton = oOleObj.Object
      End If
  Next oOleObj
End Sub

Sub Tooltip_Create(oButton As Object, X As Single, Y As Single)
' Hier das Objekt formatieren
  Dim sText As String, B As Integer, H As Integer, L As Currency
  Dim sArr() As Stringi As Integer, j As Integer, iBMax As Long
  Dim T As String

  If hTimer <> 0 Then Exit Sub                           ' Timer läuft noch
  On Error GoTo Fehler

  With oButton
      msOldBtnText = .Name
      Select Case .Name

' ##### Hier die Vorgabe der Tooltiptexte #####
' ¶ = CHR$(182) = Umbruchplatzhalter
' iBMax = Vorgabe der Textboxbreite, wenn 0, dann automatische Ermittlung
      Case "CommandButton1": sText = "Dieses ist mein erster Tooltip!": iBMax = 122
      Case "CommandButton2": sText = "Und hier¶machen wir einen Umbruch mit rein!"
      Case "CommandButton3": sText = "1. Testen¶2. Testen¶3. Testen"
      Case "CheckBox1":      sText = "Für weitere Informationen hier klicken!": iBMax = 156
' #############################################

      Case ElseExit Sub
      End Select

      sText = Replace(sText, "", vbLf)                  ' Textumbrüche setzen
      sArr = Split(sText, vbLf)
      For i = 0 To UBound(sArr)
          If iBMax = 0 Then
             L = 0
             For j = 1 To Len(sArr(i))                   ' Textbreite ermitteln
                 T = Mid$(sArr(i), j, 1)
                 L = L + 2.75
                 If InStr(1Chr$(34) & " !/()\''|,;.:1ijl", T, vbTextCompare) = 0 Then L = L + 2.5
                 If InStr(1Chr$(34) & "wm_", T, vbTextCompare) > 0 Then L = L + 0.75
                 If Asc(T) > 64 And Asc(T) < 97 Then L = L + 1.5
             Next j
             If L > B Then B = L                         ' Textboxlänge ermitteln
          End If
          H = H + 12
      Next i
      If iBMax > 0 Then B = iBMax                        ' Feste Breitenvorgabe

      Call ToolTip_Delete(.Parent)                       ' Evtl. vorhandene Tooltipbox löschen
      Y = .Top + .Height + 2 + (Y \ 2)
      X = .Left + X
      With .Parent.Shapes.AddTextbox(1, X, Y, B, H)
          .Name = "ToolTip"
          .Visible = msoFalse
          miDelayCount = 0
          With .TextFrame2.TextRange.Characters
              .Font.Size = 9
              .Font.Name = "Arial"
              .Text = sText
          End With
          With .Fill
              .ForeColor.RGB = RGB(255255210)        ' Hintergrundfarbe setzen
              .Transparency = 0
              .Solid
          End With
          With .TextFrame2
              .AutoSize = msoAutoSizeShapeToFitText      ' Textboxgröße automatisch
              .MarginLeft = 1.5:   .MarginTop = 1.5      ' Randabstände
              .MarginBottom = 1.5: .MarginRight = 1.5
          End With
      End With
  End With
  hTimer = SetTimer(0&0&10AddressOf Timer_Tick)    ' Timer setzen für nächsten Check
Fehler:
End Sub

Sub Timer_Tick()
  miDelayCount = miDelayCount + 1
  DoEvents
  GetCursorPos Pt                                        ' Mausposition holen
  On Error Resume Next
  Set oCurObj = Application.Windows(1).RangeFromPoint(Pt.X, Pt.Y)

  If Err <> 0 Then Err.Clear: Exit Sub                   ' Fehler => raus

  If TypeName(oCurObj) = "OLEObjectThen
     oCurObj.Parent.Shapes.Range("ToolTip").Visible = (miDelayCount > ciDelayTime)
     If msOldBtnText <> oCurObj.Name Then
        Call ToolTip_Delete(oCurObj.Parent)              ' Textbox löschen
        Call Tooltip_Create(oCurObj, oCurObj.X, oCurObj.Y)
     End If
  Else
     Call ToolTip_Delete(ActiveSheet)                    ' Textbox löschen
  End If
End Sub

Sub ToolTip_Delete(WSh As Worksheet)
  If hTimer <> 0 Then KillTimer 0&, hTimer: hTimer = 0   ' Timer löschen
  On Error Resume Next
  WSh.Shapes.Range("ToolTip").Delete                     ' Evtl. vorhandene Textbox löschen
End Sub
_________
viele Grüße
Karl-Heinz

Ihre Antwort
  • Bitte beschreiben Sie Ihr Problem möglichst ausführlich. (Wichtige Info z.B.: Office Version, Betriebssystem, Wo genau kommen Sie nicht weiter)
  • Bitte helfen Sie ebenfalls wenn Ihnen geholfen werden konnte und markieren Sie Ihre Anfrage als erledigt (Klick auf Häckchen)
  • Bei Crossposting, entsprechende Links auf andere Forenbeiträge beifügen / nachtragen
  • Codeschnipsel am besten über den Code-Button im Text-Editor einfügen
  • Die Angabe der Emailadresse ist freiwillig und wird nur verwendet, um Sie bei Antworten auf Ihren Beitrag zu benachrichtigen
Thema: Name: Email:



  • Bitte beschreiben Sie Ihr Problem möglichst ausführlich. (Wichtige Info z.B.: Office Version, Betriebssystem, Wo genau kommen Sie nicht weiter)
  • Bitte helfen Sie ebenfalls wenn Ihnen geholfen werden konnte und markieren Sie Ihre Anfrage als erledigt (Klick auf Häckchen)
  • Bei Crossposting, entsprechende Links auf andere Forenbeiträge beifügen / nachtragen
  • Codeschnipsel am besten über den Code-Button im Text-Editor einfügen
  • Die Angabe der Emailadresse ist freiwillig und wird nur verwendet, um Sie bei Antworten auf Ihren Beitrag zu benachrichtigen

Thema Datum  Von Nutzer Rating
Antwort
13.04.2023 08:50:06 Julaka
Solved
13.04.2023 12:34:07 Ulrich
NotSolved
13.04.2023 13:32:28 Gast79500
NotSolved
13.04.2023 21:50:11 xlKing
NotSolved
19.04.2023 13:29:27 Gast79500
NotSolved
21.04.2023 21:21:12 xlKing
NotSolved
23.04.2023 13:37:50 Gast79500
NotSolved
24.04.2023 00:36:40 xlKing
NotSolved
25.04.2023 01:22:27 Gast79500
NotSolved
25.04.2023 19:09:57 xlKing
NotSolved
26.04.2023 16:23:30 sauber....;-)....
NotSolved
13.04.2023 22:36:52 volti
Solved
14.04.2023 11:39:22 Julaka
NotSolved
14.04.2023 11:50:10 volti
Solved
14.04.2023 14:29:39 Julaka
NotSolved
Blau ToolTipText
14.04.2023 17:59:56 volti
Solved
17.04.2023 11:24:58 Julaka
Solved
21.04.2023 08:01:45 Julaka
NotSolved
21.04.2023 09:20:28 volti
NotSolved