When to load Balloon tooltips

G

Guest

Hello

I have a problem whereby I wish to setup a custom tooltip. I have the code attached to do this, it all works very wel
if you have the following code in a button click event on the form

toolTip1.SetToolTip(BtnProjSearch, "Search for a Project"
toolTip1.SetToolTip(cboSelect, "select the number of projects that you wish to select"
Dim tp As New CustomTi
tp.CustomBalloon(toolTip1

However the user shouldn't have to click on a button in order to see all the tooltips

I can't put the code in the form_load event because it doesn't work there, this is because I have the following code in my
New event, particular the calling of another form which is the database connection form

Public Sub New(
MyBase.New(

InitializeComponent(

Dim c As Component = M

Dim Myform As For
Myform = New FrmAnotherFor
Myform.Show(

End Su

Any ideas as to how I could run the tooltip code so that the tooltips will appear as soon as the form is loaded without the
user having to click on any buttons

Thanx in advanc

David Bat




#Region " Custom ToolTip Builder
Public Class CustomTi
Private Enum ToolTipIco
TTI_INFO =
TTI_WARNING =
TTI_ERROR =
End Enu

Private Enum ToolTipStyl
TTS_BALLOON = 6
WS_BORDER = 838860
TTS_NOPREFIX =
TTM_SETTITLE = 105
TTM_UPDATETIPTEXT = 103
TTM_SETTIPBKCOLOR = 104
TTM_SETTIPTEXTCOLOR = 104
End Enu

Public Sub CustomBalloon(ByVal tip As ToolTip, Optional ByVal style As Integer = 0
'/// the first 5 lines are from Divil's Balloon tip exampl
'/// 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, "Tooltip Text"
SetToolTipBackColor(hwnd, Color.GhostWhite
SetToolTipForeColor(hwnd, Color.BlueViolet
End Su

Private Sub SetToolTipCaption(ByVal tip As NativeWindow, ByVal Caption As String
Win32.SendMessage(tip.Handle, ToolTipStyle.TTM_SETTITLE, ToolTipIcon.TTI_WARNING, Caption
End Su

Private Sub SetToolTipBackColor(ByVal tip As NativeWindow, ByVal c As Color
'/// set the back color of the toolti
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 Su

Private Sub SetToolTipForeColor(ByVal tip As NativeWindow, ByVal c As Color
'/// set the back color of the toolti
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 Su

End Clas
#End Regio
'/// the Win32 Api calls to be used by the above Class..
#Region " Win32 Api Calls
Public Class Win3

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 Intege
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 Intege
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As IntPtr, ByVal nIndex As Integer) As Intege
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
 
E

Eric Lemmon

David Batt said:
Hello,

I have a problem whereby I wish to setup a custom tooltip. I have the code
attached to do this, it all works very well
if you have the following code in a button click event on the form.


toolTip1.SetToolTip(BtnProjSearch, "Search for a Project")
toolTip1.SetToolTip(cboSelect, "select the number of projects that you wish to select")
Dim tp As New CustomTip
tp.CustomBalloon(toolTip1)


However the user shouldn't have to click on a button in order to see all the tooltips.

I can't put the code in the form_load event because it doesn't work there,
this is because I have the following code in my
New event, particular the calling of another form which is the database connection form.


Public Sub New()
MyBase.New()

InitializeComponent()

Dim c As Component = Me

Dim Myform As Form
Myform = New FrmAnotherForm
Myform.Show()

End Sub


Any ideas as to how I could run the tooltip code so that the tooltips will
appear as soon as the form is loaded without the
user having to click on any buttons.


Thanx in advance

David Batt







#Region " Custom ToolTip Builder "
Public 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, "Tooltip Text")
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_WARNING, 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
 
E

Eric Lemmon

Hi David,

(Sorry for my blank posting...eager trigger finger.)

It sounds like you are leaning toward creating your own inherited ToolTip
class. However, an easier solution (conceptually) may be to just add labels
to your form. You can easily display them as ToolTips by decreasing the
font size, changing the backcolor, and setting the BorderStyle to
FixedSingle.

Take care,

Eric

David Batt said:
Hello,

I have a problem whereby I wish to setup a custom tooltip. I have the code
attached to do this, it all works very well
if you have the following code in a button click event on the form.


toolTip1.SetToolTip(BtnProjSearch, "Search for a Project")
toolTip1.SetToolTip(cboSelect, "select the number of projects that you wish to select")
Dim tp As New CustomTip
tp.CustomBalloon(toolTip1)


However the user shouldn't have to click on a button in order to see all the tooltips.

I can't put the code in the form_load event because it doesn't work there,
this is because I have the following code in my
New event, particular the calling of another form which is the database connection form.


Public Sub New()
MyBase.New()

InitializeComponent()

Dim c As Component = Me

Dim Myform As Form
Myform = New FrmAnotherForm
Myform.Show()

End Sub


Any ideas as to how I could run the tooltip code so that the tooltips will
appear as soon as the form is loaded without the
user having to click on any buttons.


Thanx in advance

David Batt







#Region " Custom ToolTip Builder "
Public 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, "Tooltip Text")
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_WARNING, 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top