Solved

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

Posted on 2011-09-17
11
433 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
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
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
 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

828 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