PDA

View Full Version : Hovering text not disappearing after click



mbm123
04-03-2011, 11:55 PM
I have hovering textbox that appears when i put the mouse icon over a button. It disapears when the mouse icon is anywhere else. The problem is, after a click it should disappear as well but it doesnt. It requires to click somewhere else and then move the cursor over the button and off it.

code:


Private Sub class_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If X > class.Width Or X < 0 Then
ActiveSheet.Shapes("clabel").Visible = False
Else
If Y < 0 Or Y > class.Height Then
ActiveSheet.Shapes("clabel").Visible = False
Else
ActiveSheet.Shapes("clabel").Visible = True
End If
End If
End Sub


and code for click


Private Sub class_Click()
**stuff, not relevant**
ActiveSheet.Shapes("clabel").Visible = False
End Sub


I could use some help... it is really annoying and seems unproffesional when i submit it.

mikerickson
04-04-2011, 01:30 AM
Adding a module wide variable worked for me in a userform.
You may need to fudge with the edgeWidth value
Dim Flag As Boolean

Private Sub CommandButton1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single)
Dim inBorder As Boolean
Dim edgeWidth As Long: edgeWidth = 10

inBorder = (Application.Min(x, Me.CommandButton1.Width - x, y, Me.CommandButton1.Height - y) <= edgeWidth)

If inBorder Then
Flag = True
TextBox1.Visible = False
Else
If Flag Then
TextBox1.Visible = True
End If
End If
End Sub

Private Sub CommandButton1_Click()
Flag = False
TextBox1.Visible = False
End Sub

Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single)
TextBox1.Visible = False
End Sub


Have you considered the ToolTipText rather than a Text Box?

mbm123
04-04-2011, 02:27 AM
I couldn't find a guide on ToolTipText. Can you link me or give a short explnation?

Thanks for your code btw, i'll try it.

mikerickson
04-04-2011, 06:50 AM
Where is the command button? on a userform?
Userform controls have a property .ControlTipText that will be displayed in a window if the user hovers over the control.

CommandButton1.ControlTipText = "Have some mini-help."

mbm123
04-04-2011, 06:56 AM
The button is on the sheet itself

I checked the tooltip and it's great, too bad i can't have in on a out-of-form command button :/

mikerickson
04-04-2011, 07:47 AM
Is your command button a Forms button or ActiveX. (I'd guess ActiveX)

mikerickson
04-04-2011, 07:59 AM
If its ActiveX,
create a Label with Caption="" and BackStyle = fmBackStyleTransparent
size the label so that it is slightly larger than the Command Button (Label1.Width = CommandButton1.Width + 8, height similarly) and put the Command button on top of the Label, then code like this should do what you want.
Dim clickFlag As Boolean

Private Sub CommandButton1_Click()
clickFlag = True
TextBox1.Visible = False
End Sub

Private Sub CommandButton1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If Not clickFlag Then
TextBox1.Visible = True
End If
End Sub

Private Sub Label1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
clickFlag = False
TextBox1.Visible = False
End Sub

mbm123
04-04-2011, 11:44 AM
mikericson - it seems ok and working but isn't there a way to do it just like the tooltip? your way is a bit manipulative (i like it though)

mikerickson
04-04-2011, 12:17 PM
Since ActiveX controls don't have a tool tip, we have to emulate one.