Solved

VS 2010 VB  Stop ToolTip from Showing On Button When Text is > Button Width

Posted on 2011-09-17
11
429 Views
Last Modified: 2012-05-12
I have a button on a form. AutoElipses=true.  The button text length is greater than the button width.  When the mouse is over the button a tooltip appears showing the entire text of the button.  How do stop/prevent the tooltip from showing when the text is greater than the button width.  Been on it for a while with no results - need help.
0
Comment
Question by:gosonic
  • 5
  • 4
  • 2
11 Comments
 
LVL 40
ID: 36554878
This feature is not built into the Button class, so somebody probably added a tooltip.

If it was done in the standard way, look for a property called someting like ToolTip on ToolTip1 in the properties of the button and empty it.

If it was something built in a non standard way, make a search in all the solution for the text that appears on the tooltip. That will show you the line that initialize the thing.
0
 

Author Comment

by:gosonic
ID: 36554936
No tooltip in the project.   I just created a new project  and put one button on the form (windows form) and set the autoelipse = true.  Then made the button text longer than what could be displayed.
When I mouse over the button the entire text shows in a tooltip style beside the button.

If is set AutoEllipisis=false then the tooltip does not display.  However I need to keep the AutoElisisis set to True in my project.
0
 

Author Comment

by:gosonic
ID: 36554953
I was able to get this code to work with a Label when there was overflow but it does not work with the button.

            Dim field As Reflection.FieldInfo = GetType(Label).GetField("showToolTip", Reflection.BindingFlags.NonPublic Or Reflection.BindingFlags.Instance)
            If field IsNot Nothing Then
                field.SetValue(Me.Label1, False)
            End If
0
 
LVL 40
ID: 36554956
Thanks, I learned about a new property.

Why do you need to set it to True if you do not want the feature?
0
 

Author Comment

by:gosonic
ID: 36554962
I know... it should not matter but in this case it just needs to be that way if I can figure it out.
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 36554971
This ~weird~ combination seems to work for some reason.

Add a ToolTip control to the Form.
Set the ToolTip() property for the Button to ~something~ (could even be a space).
Now select the ToolTip control and set the Active() property to False.

Next, use the code below to suppres the WM_MOUSEHOVER message for the button.
*Note that this code does not work by itself...but it does when combine with an ~inactive~ ToolTip control (above)!
Public Class Form1

    Private myBtn As MyButton

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        myBtn = New MyButton(Button1)
    End Sub

End Class

Public Class MyButton
    Inherits NativeWindow

    Private Const WM_MOUSEHOVER As Integer = &H2A1

    Public Sub New(ByVal btn As Button)
        If Not IsNothing(btn) Then
            Me.AssignHandle(btn.Handle)
        End If
    End Sub

    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        Select Case m.Msg
            Case WM_MOUSEHOVER
                m.Result = IntPtr.Zero
                Debug.Print("WM_MOUSEHOVER")
                Exit Sub ' Suppress the mouse hover message...

        End Select
        MyBase.WndProc(m)
    End Sub

End Class

Open in new window

0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 36554984
Ha!...even weirder, this also works with the ToolTIp control still Active:
*VS2010 in Win 7 x64
Public Class Form1

    Private myBtn As MyButton

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        myBtn = New MyButton(Button1)
    End Sub

End Class

Public Class MyButton
    Inherits NativeWindow

    Public Sub New(ByVal btn As Button)
        If Not IsNothing(btn) Then
            Me.AssignHandle(btn.Handle)
        End If
    End Sub

End Class

Open in new window

0
 

Accepted Solution

by:
gosonic earned 0 total points
ID: 36555041
Thanks
0
 

Author Closing Comment

by:gosonic
ID: 36579010
Thanks again
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 36555072
So...which solution worked?   You've selected your own comment as the solution...
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 36580139
How ironic that the Accepted solution is your own, which says "Thanks".
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now