Solved

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

Posted on 2011-09-17
11
431 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
DevOps Toolchain Recommendations

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

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
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 …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 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

11 Experts available now in Live!

Get 1:1 Help Now