Giter Site home page Giter Site logo

dxultimatesamples / richtooltip Goto Github PK

View Code? Open in Web Editor NEW
4.0 1.0 0.0 277 KB

A DevExpress SuperTip item extension that allows to display tooltip content with column formatting and arbirtrary rich-text content

C# 100.00%
devexpress winforms tooltip richtext rtf

richtooltip's Introduction

DxUltimate Sample: RichText ToolTip for DevExpress

1. Introduction

I while ago I found myself in a situation where I needed to be able to display -formatted text in a ToolTip which is aligned in columns. When you don't find it visually acceptable to accomodate with the clumsy appearance of a monospaced font, there are not really any options left - not even with the DX SuperTip. It allows some simplified HTML markup for formatting but it doesn't support 'real' HTML/CSS for table or column layouts.

2. Impossible?

DX Support says so - there are quite a few tickets asking for that or similar:

3. Solution

From the perspective of the usage side, it would have been most convenient to modify the tooltip display in a way that it supports an extended set of html features for rendering, but developing that from scratch is a ridiculous amount of work and using one of the established browser engine to offload the rendering would introduce dependencies, bloat-up the application and waste resources - just to display a tooltip.. That's how I came to using RichText instead. RichText rendering is fast and almost part of the Windows OS - at least, the related dlls are typically loaded already, no matter whether we use them for tooltip display or not.

This solution consists of two parts:

Part #1: Rendering RTF text inside a SuperTip

This is done in full accordance to the DX pattern: RichToolTipItem is implemented as an additional descendant of BaseToolTipItem The RichToolTipItem is accompanied by appropriate implementations of ViewInfo and ItemPainter

RichToolTipItem Properties
  • LeftIndent
  • MaxWidth (inherited)
  • MaxHeight
  • Text - RTF text

Part #2: Programmatically creating RTF for display

RichTextTableBuilder is a helper that creates an RTF document containing a table layout.

Its CreateTable() method takes a 2-dimensional string array for the table data and a DX AppearanceObject.

The RTF is generated in a way that the styles are exactly matching

  • the currently active Skin plus
  • the settings applied via the ToolTipManager's Appearance setting.

Screenshot 4 demonstrates this by showing two tooltip sections: a regular one and a RichToolTip section. Both are rendered ín the exact same way.

4. Examples

Screenshot 1

Tooltip shows the content of the current RichText document:

Screenshot1

Screenshot 2

The DataGrid contents are converted to a RichText table with three columns which is shown in the Tooltip:

Screenshot2

Screenshot 3

The RichText content is rendered with a transparent background and doesn't affect the Tooltip background, even when it is using a gradient:

Screenshot3

Screenshot 4

The row marked with 'S' is a regular Tooltip section. As long as the RTF text doesn't have inline styles, it renders with the Appearance settings (font, colors, etc.) defined in the Tooltip:

Screenshot4

5. Usage

Create a RichToolTipItem

            var tip = new SuperToolTip();
            tip.Items.AddTitle(title);
            tip.Items.AddSeparator();

            var richItem = new RichToolTipItem();

            richItem.Text = this.richEditControl1.RtfText;
            tip.Items.Add(richItem);

Create a RichText Document with Table Layout

            var cells = new string[this.list.Count,3];

            for (int i = 0; i < this.list.Count; i++)
            {
                cells[i, 0] = this.list[i].Col1;
                cells[i, 1] = this.list[i].Col2;
                cells[i, 2] = this.list[i].Col3;
            }

            var richItem = new RichToolTipItem();
            richItem.MaxWidth = 600;
            richItem.Appearance.Assign(this.defaultToolTipController1.DefaultController.Appearance);

            richItem.LeftIndent = 8;
            var appearance = richItem.GetPaintAppearance();
            var rtf = RichTextTableBuilder.CreateTable(cells, appearance);

            richItem.Text = rtf;

            tip.Items.Add(richItem);
            tip.MaxWidth = 600;

richtooltip's People

Contributors

matthiasmoetje avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.