开发者

How to add a tooltip to the 'X' in a Windows Form?

I am currently programming within Visual Studio 2008 with VB.Net. I have been asked to add a tooltip to the upper closing button (the 'X' in the top right of the form next to the maximize and minimize buttons).

Is there anyway in which I am able to do this?

Solution:

I solved this using @Saman answer and changing it slightly so I figured I would post it in case anyone is having a problem solved by this or by @Saman's exact answer.

First I added a ToolTip from the toolbox to my form. 开发者_Python百科I didn't have to disable the tooltips for the minimize, maximize and close and it usually doesn't appear. I then used @Saman function with one minor change:

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)

    If m.Msg = 160 And m.WParam = 20 Then
        ToolTip1.SetToolTip(Me, "Save and Close")
    Else
        MyBase.WndProc(m)
    End If
End Sub

As you can see instead of using his ToolTip1.Show() I used ToolTip1.SetToolTip(). I found with the show it worked infrequently, yet with the setToolTip it set the tooltip of the ('X') close button to my new text ("Save and Close") and thus it shows up whenever my mouse goes over the close button.


at first you must disable tooltips for Minimize, Maximize, and Close button here some useful links: HOW To Disable ToolTips for Minimize, Maximize, and Close button

and here: Disable tooltips for Minimize, Restore and Close button

then you can use this code for show your tooltip:

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)

        If m.Msg = 160 And m.WParam = 20 Then
            ToolTip1.Show("CLoseeeeee", Me)
        Else
            MyBase.WndProc(m)
        End If
End Sub


I don't think that is possible within .Net (that is, with simple managed code). The close, minimize, and maximize buttons are defined by the OS, outside of the .Net CLR. (You can determine their visibility on a form, but I think that's about it.)

If adding a tooltip is possible, it would need to be done with calls to unmanaged Windows API'S.

Try looking here for a start: http://pinvoke.net

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜