Displaying tooltip on mouse hover of a text

前端 未结 9 1043
盖世英雄少女心
盖世英雄少女心 2020-11-29 07:22

I want to display a tooltip when the mouse hovers over a link in my custom rich edit control. Consider the following text:

We all sleep

9条回答
  •  广开言路
    2020-11-29 08:15

    As there is nothing in this question (but its age) that requires a solution in Windows.Forms, here is a way to do this in WPF in code-behind.

    TextBlock tb = new TextBlock();
    tb.Inlines.Add(new Run("Background indicates packet repeat status:"));
    tb.Inlines.Add(new LineBreak());
    tb.Inlines.Add(new LineBreak());
    Run r = new Run("White");
    r.Background = Brushes.White;
    r.ToolTip = "This word has a White background";
    tb.Inlines.Add(r);
    tb.Inlines.Add(new Run("\t= Identical Packet received at this time."));
    tb.Inlines.Add(new LineBreak());
    r = new Run("SkyBlue");
    r.ToolTip = "This word has a SkyBlue background";
    r.Background = new SolidColorBrush(Colors.SkyBlue);
    tb.Inlines.Add(r);
    tb.Inlines.Add(new Run("\t= Original Packet received at this time."));
    
    myControl.Content = tb;
    

提交回复
热议问题