ARTICLE

How to use ToolTip in WPF using VB.NET

Posted by Rohatash Kumar Articles | WPF using VB.NET February 02, 2011
In this article we will learn how to use ToolTip in WPF using VB.NET.
Download Files:
 
Reader Level:

In this article we will learn how to use ToolTip in WPF using VB.NET.

ToolTip

ToolTip is used to display explanatory text when the mouse rest on a control or window. This property is helpful in providing a quick help to users or display information when the user moves the pointer over an associated control.

A simple ToolTip

Drag and drop a Button control on the form. The form looks like this.

t1.gif

Figure 1.

Now select Button control and press F4 to property window and set it ToolTip property.

t2.gif

Figure 2.

Now run the application and moves the mouse on the control and test it.

t5.gif

Figure 3.

To show much more elaborate ToolTip.

XAML code

<Grid>

 <Button Height="23" HorizontalAlignment="Left" Margin="125,0,0,175" Name="Button2" VerticalAlignment="Bottom" Width="252" Content="Button">

            <Button.ToolTip>

           <ToolTip>

            <StackPanel>

           <TextBlock HorizontalAlignment="Left">This is a much more</TextBlock>

            <TextBlock HorizontalAlignment="Center">

              <Italic>

           <Bold>elaborate</Bold>

            </Italic>

            </TextBlock>

           <TextBlock HorizontalAlignment="Right">tooltip!here</TextBlock>

            </StackPanel>

                </ToolTip>

            </Button.ToolTip>

        </Button>

    </Grid>

Now run the application and moves the mouse on the control and test it.

t3.gif

Figure 4.

Graphical ToolTip

XAML code

<Window x:Class="MainWindow"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    Title="MainWindow" Height="350" Width="525">

    <Grid>

        <Grid.Resources>

            <LinearGradientBrush x:Key="Visible" StartPoint="0,0" EndPoint="1,0">

                <GradientStop Color="Red" Offset="0.15" />

                <GradientStop Color="Green" Offset="0.2" />

            </LinearGradientBrush>

        </Grid.Resources>

        <Button Content="Button with a graphical tooltip." MaxHeight="25" Margin="59,10,76,10">

            <Button.ToolTip>

                <StackPanel>

                    <Rectangle Canvas.Top="10" Canvas.Left="20"

                   Stroke="Black" StrokeThickness="4"

                   Height="80" Fill="{StaticResource Visible}"  Width="70" ToolTip="A rectangle."/>

                    <TextBlock HorizontalAlignment="Left">Please press the Button</TextBlock>

                </StackPanel>

            </Button.ToolTip>

        </Button>

    </Grid>

</Window>

 

Now run the application and moves the mouse on the control and test it.


t4.gif 

Figure 5.

Login to add your contents and source code to this article
share this article :
post comment
 
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
Team Foundation Server Hosting
Become a Sponsor