Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 441
  • Last Modified:

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

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
gosonic
Asked:
gosonic
  • 5
  • 4
  • 2
1 Solution
 
Jacques Bourgeois (James Burger)Commented:
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
 
gosonicAuthor Commented:
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
 
gosonicAuthor Commented:
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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
Jacques Bourgeois (James Burger)Commented:
Thanks, I learned about a new property.

Why do you need to set it to True if you do not want the feature?
0
 
gosonicAuthor Commented:
I know... it should not matter but in this case it just needs to be that way if I can figure it out.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
 
gosonicAuthor Commented:
Thanks
0
 
gosonicAuthor Commented:
Thanks again
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
So...which solution worked?   You've selected your own comment as the solution...
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
How ironic that the Accepted solution is your own, which says "Thanks".
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 5
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now