Results 1 to 4 of 4

Thread: Tool Tip [RESOLVED]

  1. #1

    Thread Starter
    Addicted Member Hole-In-One's Avatar
    Join Date
    Mar 2003
    Location
    Minnesota
    Posts
    195

    Tool Tip [RESOLVED]

    This was in the "codebank" thanks to "dynamic_sysop":

    Code:
        Dim tp As New CustomTip()
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            ToolTip1.SetToolTip(Button1, Button1.Text)
            tp.CustomBalloon(ToolTip1)
        End Sub
    
    End Class
    
    '/// the Class that will build your Custom ToolTip .  .  .
    #Region " Custom ToolTip Builder "
    Public[/color] Class CustomTip
        Private Enum ToolTipIcon
            TTI_INFO = 1
            TTI_WARNING = 2
            TTI_ERROR = 3
        End Enum
    
        Private Enum ToolTipStyle
            TTS_BALLOON = 64
            WS_BORDER = 8388608
            TTS_NOPREFIX = 2
            TTM_SETTITLE = 1056
            TTM_UPDATETIPTEXT = 1036
            TTM_SETTIPBKCOLOR = 1043
            TTM_SETTIPTEXTCOLOR = 1044
        End Enum
    
        Public Sub CustomBalloon(ByVal tip As ToolTip, Optional ByVal style As Integer = 0)
            '/// the first 5 lines are from Divil's Balloon tip example
            '/// i've marked them with a  *  at the end . 
            '/// start of  * 
            Dim hwnd As NativeWindow = DirectCast(GetType(ToolTip).GetField("window", Reflection.BindingFlags.NonPublic Or Reflection.BindingFlags.Instance).GetValue(tip), NativeWindow) '///  * 
            style = Win32.GetWindowLong(hwnd.Handle, Win32.GWL_STYLE) '///  * 
            style = style Xor ToolTipStyle.WS_BORDER '///  * 
            style = style Or ToolTipStyle.TTS_BALLOON Or ToolTipStyle.TTS_NOPREFIX '///  * 
            Win32.SetWindowLong(hwnd.Handle, Win32.GWL_STYLE, style) '///  * 
            '/// end of  * 
            '/// the remaining code  ,  for colors / caption / icon is all by me  (  Dynamic Sysop  ) 
            '/// no to set the caption / icon & colors up .  .  . 
            SetToolTipCaption(hwnd, "this is the tooltip Caption")
            SetToolTipBackColor(hwnd, Color.GhostWhite)
            SetToolTipForeColor(hwnd, Color.BlueViolet)
    
        End Sub
    
        Private Sub SetToolTipCaption(ByVal tip As NativeWindow, ByVal Caption As String)
            Win32.SendMessage(tip.Handle, ToolTipStyle.TTM_SETTITLE, ToolTipIcon.TTI_INFO, Caption)
        End Sub
    
        Private Sub SetToolTipBackColor(ByVal tip As NativeWindow, ByVal c As Color)
            '/// set the back color of the tooltip
            Dim Col As Integer = ColorTranslator.ToWin32(Color.FromArgb(Convert.ToInt32(c.R), Convert.ToInt32(c.G), Convert.ToInt32(c.B)))
            Win32.SetToolColors(tip.Handle, ToolTipStyle.TTM_SETTIPBKCOLOR, Col, 0)
        End Sub
    
        Private Sub SetToolTipForeColor(ByVal tip As NativeWindow, ByVal c As Color)
            '/// set the back color of the tooltip
            Dim Col As Integer = ColorTranslator.ToWin32(Color.FromArgb(Convert.ToInt32(c.R), Convert.ToInt32(c.G), Convert.ToInt32(c.B)))
            Win32.SetToolColors(tip.Handle, ToolTipStyle.TTM_SETTIPTEXTCOLOR, Col, 0)
        End Sub
    
    End Class
    #End Region
    '/// the Win32 Api calls to be used by the above Class .  .  .
    #Region " Win32 Api Calls "
    Public Class Win32
    
        Public Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As String) As Integer
        Public Declare Function SetToolColors Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
        Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As IntPtr, ByVal nIndex As Integer) As Integer
        Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As IntPtr, ByVal nIndex As Integer, ByVal dwNewLong As Integer) As Integer
        Public Const GWL_STYLE As Integer = (-16)
    
    End Class
    #End Region

    My Question is, how do I get this to work when my button that I want a tooltip for, is on a panel?
    Last edited by Hole-In-One; Mar 8th, 2004 at 05:42 PM.

  2. #2
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    you could do a For Each loop on the panel's controls to find your button , or Panel.Controls.IndexOf(button1) '/// your button's name where it says button1
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  3. #3

    Thread Starter
    Addicted Member Hole-In-One's Avatar
    Join Date
    Mar 2003
    Location
    Minnesota
    Posts
    195
    Well I guess my question is, if I put a button on a form the code works great. But if I put ny button on a panel the code doesn't work. Why?

    'Button on the form
    ToolTip1.SetToolTip(btnTimeCard, btnTimeCard.Text)
    Dim tp As New CustomTip
    tp.CustomBalloon(ToolTip1)
    Works!



    'Button on the panel
    ToolTip1.SetToolTip(btnTimeCard, btnTimeCard.Text)
    Dim tp As New CustomTip
    tp.CustomBalloon(ToolTip1)
    Don't work?

    What I mean by don't work is that I still get a tooltip to show, just not the fancy one that you've made the class for.

  4. #4

    Thread Starter
    Addicted Member Hole-In-One's Avatar
    Join Date
    Mar 2003
    Location
    Minnesota
    Posts
    195
    Nevermind, I figured it out.

    Its a long story(Not even worth explaining )

    Your code works great.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width