WPF Use ToolTip in VB.NET

In this article we will learn how to use ToolTip in WPF using VB.NET.
  • 3219
Download Files:
 

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.

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.