Solved

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

Posted on 2011-09-17
11
435 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
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 86

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 86

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 86

Expert Comment

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

Expert Comment

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

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

733 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