views:

275

answers:

1

Hello,

I have .NET WPF application and one of requirement is that user may select and copy text outside of my application. My application has to respond to clipboard event. Look up word from dictionary and next to selected text show tooltip with word's translation.

As I understand this has to be accomplished using calls to Windows API.

I have found example code, that accomplishes this task.

http://www.codeproject.com/KB/miscctrl/tooltipzen.aspx?fid=4069&df=90&mpp=25&noise=3&sort=Position&view=Quick&fr=26

One of my first ideas, was to convert this example into library that I can call from .NET application (basically my library would contain 2 methods: show and hide tooltip). Unfortunately my VC++ knowledge is next to nothing.

Is there any other way to solve this problem?

Thank You very much.

+1  A: 

There is nothing magical about tooltips - they are just windows with a thin border, no title, yellowish background and always on top style.

You can easily duplicate those in WPF:

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        ResizeMode="NoResize" 
        SizeToContent="WidthAndHeight"
        Background="Yellow" 
        WindowStyle="None" 
        Topmost="True">
    <Border BorderBrush="Black" BorderThickness="1">
        <TextBlock Text="Tooltip text"/>
    </Border>
</Window>

And now you can use all of Window's methods and properties to move, resize, show and hide your "tooltip", as a bonus you can also insert more advanced context into the tooltip (images, buttons, hyperlinks, your logo) or make it look more intresting.

Nir
You are right. I'm making my life harder. Will user Your solution. Thank You
Daniil Harik
except that they might not be yellow, or might have round corners like on vista
Anders
Anders, The tooltip is a normal everyday window with some styles you can apply yourself, the color is stored in the registry (I forgot where) and getting rounded corners is easy using the SetWindowRgn function.
Nir