ToolTips Cool
[ToolTips al Estilo XP]

Fecha: 18/Nov/2004 (17/Nov/2004)
Autor: Angel Enrique Ruiz Pastor (Vzla), aruiz1979@gmail.com

 


Este código nos muestra como hacer un ToolTips más llamativo para que nuestra aplicación sea mas agradable Visualmente al usuario.

Abra un nuevo proyecto, En Proyectos de Visual Basic seleccione la plantilla Aplicación para Windows.

En la Barra de Herramientas Seleccione Proyecto se le desplegara una lista  seleccione Agregar Módulo.

Agregue 3 Button al Formulario y no le cambie el Nombre, Déjelo como Button1, Button2 y Button3, cambie es la propiedad Text de cada uno de los Button de la siguiente manera:

Button1.Text="Información"

Button2.Text="Advertencia"

Button3.Text="Error"

 
En el Modulo copie y pegue este código:
 
'****************************************************************************************
'* Código realizado por Angel Ruiz © (Venezolano)                                       *
'****************************************************************************************
Imports System.Runtime.InteropServices

Module Module1

    Public Result As Boolean

    <StructLayout(LayoutKind.Sequential)> Public Structure NOTIFYICONDATA

        Dim cbSize As Int32

        Dim hwnd As IntPtr

        Dim uID As Int32

        Dim uFlags As Int32

        Dim uCallbackMessage As IntPtr

        Dim hIcon As IntPtr

        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=128)> Dim szTip As String

        Dim dwState As Int32

        Dim dwStateMask As Int32

        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=256)> Dim szInfo As String

        Dim uVersion As Int32

        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=64)> Dim szInfoTitle As String

        Dim dwInfoFlags As Int32

    End Structure

    Public Const NIF_MESSAGE As Int32 = &H1

    Public Const NIF_ICON As Int32 = &H2

    Public Const NIF_STATE As Int32 = &H8

    Public Const NIF_INFO As Int32 = &H10

    Public Const NIF_TIP As Int32 = &H4

    Public Const NIM_ADD As Int32 = &H0

    Public Const NIM_MODIFY As Int32 = &H1

    Public Const NIM_DELETE As Int32 = &H2

    Public Const NIM_SETVERSION As Int32 = &H4

    Public Const NOTIFYICON_VERSION As Int32 = &H5

    Public Const NIS_HIDDEN = &H1

    Public Const NIS_SHAREDICON = &H2

    Public Const NIIF_ERROR = &H3

    Public Const NIIF_INFO = &H1

    Public Const NIIF_NONE = &H0

    Public Const NIIF_WARNING = &H2

    Public Const NIM_SETFOCUS = &H4

    Public Const NIIF_GUID = &H5

    Public Declare Function Shell_NotifyIcon Lib "shell32.dll" _

    Alias "Shell_NotifyIconA" (ByVal dwMessage As Int32, _

    ByRef lpData As NOTIFYICONDATA) As Boolean

    Public uNIF As NOTIFYICONDATA

    Public Sub AddIcon(ByRef Form As System.Windows.Forms.Form)

        With uNIF

            .cbSize = Marshal.SizeOf(uNIF)

            .hwnd = Form.Handle

            .uID = 1

            .uFlags = NIF_MESSAGE Or NIF_ICON Or NIF_TIP

            .uCallbackMessage = New IntPtr(&H500)

            .uVersion = NOTIFYICON_VERSION

            .hIcon = Form.Icon.Handle

        End With

        Result = Shell_NotifyIcon(NIM_ADD, uNIF)

    End Sub

    Public Sub WNotification(ByVal sMessage As String)

        With uNIF

            .uFlags = NIF_INFO

            .uVersion = 1000

            .szInfoTitle = "Advertencia"

            .szInfo = sMessage

            .dwInfoFlags = NIIF_WARNING

        End With

        Result = Shell_NotifyIcon(NIM_MODIFY, uNIF)

    End Sub

    Public Sub ENotification(ByVal sMessage As String)

        With uNIF

            .uFlags = NIF_INFO

            .uVersion = 1000

            .szInfoTitle = "Error"

            .szInfo = sMessage

            .dwInfoFlags = NIIF_ERROR

        End With

        Result = Shell_NotifyIcon(NIM_MODIFY, uNIF)

    End Sub

    Public Sub INotification(ByVal sMessage As String)

        With uNIF

            .uFlags = NIF_INFO

            .uVersion = 1000

            .szInfoTitle = "Información"

            .szInfo = sMessage

            .dwInfoFlags = NIIF_INFO

        End With

        Result = Shell_NotifyIcon(NIM_MODIFY, uNIF)

    End Sub

    Public Sub RemoveIcon(ByRef Form As System.Windows.Forms.Form)

        With uNIF

            .cbSize = Marshal.SizeOf(uNIF)

            .hwnd = Form.Handle()

            .uID = 1

        End With

        With Shell_NotifyIcon(NIM_DELETE, uNIF)

        End With

    End Sub

End Module

-------------------------------------------------------------------------------------------------------

Ahora vaya al Formulario y haga doble click sobre el:
 
En el Evento Load del Formulario Copie y pegue lo siguiente:

AddIcon(Me)

Quedaría de la siguiente forma:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        AddIcon(Me)

    End Sub

Ahora en el Evento Closing del Formulario Copie y pegue lo siguiente:

RemoveIcon(Me)
 
Quedaría de la siguiente forma:

      Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing

        RemoveIcon(Me)

    End Sub

Ahora en el Evento Click del Button1 Copie y pegue lo siguiente:

 INotification("Tu Mensaje")
 
Quedaría de la siguiente forma:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        INotification("Tu Mensaje")

End Sub

Ahora en el Evento Click del Button2 Copie y pegue lo siguiente:

  WNotification("Tu Mensaje")
 
Quedaría de la siguiente forma:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        WNotification("Tu Mensaje")

End Sub

Ahora en el Evento Click del Button3 Copie y pegue lo siguiente:

  ENotification("Tu Mensaje")
 
Quedaría de la siguiente forma:

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

        ENotification("Tu Mensaje")

End Sub

 
 
Ahora ejecute su aplicación presionando F5.

 


ir al índice

Fichero con el código de ejemplo: ar_ToolTipsCool.zip - 21,2 KB