HypernovaDesktop Components · docs
Binarymission
WinForms › Tool Tip › BinaryToolTip

BinaryToolTip

class.NET 6 / 8 / 10.NET Framework 4.8Binarymission.WinForms.Controls.Popups

A tool tip component that gives controls a tip with a title, an icon and text, drawn as a rectangle or as a rounded balloon pointing at the mouse pointer, with a soft drop shadow and colours of your choosing.

public sealed partial class BinaryToolTip : Component, IExtenderProvider

Inherits from / implements: Component, IExtenderProvider

Remarks

Drop one on a form and every control on it gains BinaryToolTipText, BinaryToolTipTitle, BinaryToolTipIcon and BinaryToolTipStyle properties "on binaryToolTip1" in the Properties window; in code, call SetBinaryToolTipText and its companions with the control.

When tips show

A control shows a tip once it has text. The tip appears when the pointer has rested on the control for ToolTipHoverDelay, just below the pointer, and closes after ToolTipHideDelay, or as soon as the pointer moves, leaves the control or presses a button. Moving on to another control within ToolTipReshowDelay shows that control's tip at once. A tip that would run off the screen is moved above the pointer or to the left.

Appearance

Each control's tip is a BinaryToolTipStyle.Standard rectangle or a BinaryToolTipStyle.BalloonType balloon (ToolTipTipStyle, or SetBinaryToolTipStyle per control). The colours, fonts, shadow and wrapping are set once on the component and shared by all its tips: BackColor, BorderColor, TitleForeColor, TextForeColor, ToolTipTextFont, ShadowOffset, ShadowColor, CustomWidth.

Examples

Balloon tips on a customer form's fields, in a cool blue.

using System.Drawing;
using System.Windows.Forms;
using Binarymission.WinForms.Controls.Popups;

public class CustomerForm : Form
{
    private readonly BinaryToolTip _tips;
    private readonly TextBox _vatNumber = new TextBox { Location = new Point(120, 16), Width = 160 };
    private readonly TextBox _creditLimit = new TextBox { Location = new Point(120, 48), Width = 100 };

    public CustomerForm()
    {
        _tips = new BinaryToolTip
        {
            ToolTipTipStyle = BinaryToolTipStyle.BalloonType,
            BackColor = Color.AliceBlue,
            BorderColor = Color.SteelBlue,
            TitleForeColor = Color.MidnightBlue,
            CustomWidth = 240,
            ToolTipHoverDelay = 400
        };

        _tips.SetBinaryToolTipTitle(_vatNumber, "VAT number");
        _tips.SetBinaryToolTipText(_vatNumber, "The customer's VAT registration number, for example GB123456789. Leave blank for private customers.");
        _tips.SetBinaryToolTipIcon(_vatNumber, SystemIcons.Information.ToBitmap());

        _tips.SetBinaryToolTipTitle(_creditLimit, "Credit limit");
        _tips.SetBinaryToolTipText(_creditLimit, "The most the customer may owe at any time, in pounds sterling.");

        Controls.Add(_vatNumber);
        Controls.Add(_creditLimit);
    }
}

See also

Members at a glance

Constructors
BinaryToolTipInitialises a new tool tip component with standard rectangular tips in light yellow with a brown outline.
BinaryToolTipInitialises a new tool tip component, as the Windows Forms designer creates it.
Properties
AutomaticMultiLineSupportGets or sets whether long text wraps at CustomWidth rather than running on in one line.
BackColorGets or sets the colour that fills the tip.
BalloonEdgeCurveFactorGets or sets how rounded the corners of a balloon tip are.
BorderColorGets or sets the colour of the line round the tip.
CustomWidthGets or sets the width at which the tip's text wraps onto a new line.
ShadowColorGets or sets the colour the tip's drop shadow is drawn in.
ShadowOffsetGets or sets how far the tip's drop shadow falls to the right and below the tip.
TextForeColorGets or sets the colour of the tip's main text.
TitleForeColorGets or sets the colour of the tip's title.
TitleWillBeBoldGets or sets whether the tip's title is bold.
TitleWillBeUnderlinedGets or sets whether the tip's title is underlined.
ToolTipHideDelayGets or sets how long a tip stays on screen if the pointer stays still.
ToolTipHoverDelayGets or sets how long the mouse pointer must rest on a control before its tip appears.
ToolTipReshowDelayGets or sets how long after one tip closes the pointer can move onto another control and see its tip at once, without waiting for ToolTipHoverDelay.
ToolTipTextFontGets or sets the font of the tip's main text.
ToolTipTipStyleGets or sets the shape of tips for controls that have not been given a style of their own.
Methods
DisposeCloses any open tip and releases the resources the component holds.
GetBinaryToolTipIconGets the picture shown in a control's tip.
GetBinaryToolTipStyleGets the shape of a control's tip.
GetBinaryToolTipTextGets the main text of a control's tip.
GetBinaryToolTipTitleGets the title of a control's tip.
SetBinaryToolTipIconSets a small picture shown at the start of a control's tip, beside the title.
SetBinaryToolTipStyleSets the shape of one control's tip, overriding ToolTipTipStyle.
SetBinaryToolTipTextSets the main text of a control's tip, and so gives the control a tip.
SetBinaryToolTipTitleSets the title shown above the text of a control's tip.

Constructors

BinaryToolTip

public BinaryToolTip()

Initialises a new tool tip component with standard rectangular tips in light yellow with a brown outline.

BinaryToolTip

public BinaryToolTip(IContainer ic) : this()

Initialises a new tool tip component, as the Windows Forms designer creates it.

Parameters
ic
The form's component container.

Properties

AutomaticMultiLineSupport

public bool AutomaticMultiLineSupport

Gets or sets whether long text wraps at CustomWidth rather than running on in one line.

Value
true to wrap the text at CustomWidth. The default is true.
Remarks

With wrapping off, the tip is as wide as the longest line, and lines break only where the text has line breaks.

BackColor

public Color BackColor

Gets or sets the colour that fills the tip.

Value
The fill colour. The default is Color.LightYellow.
See also

BalloonEdgeCurveFactor

public int BalloonEdgeCurveFactor

Gets or sets how rounded the corners of a balloon tip are.

Value
The size of each rounded corner as a percentage of the balloon's width and height. The default is 15.
Designer category
Appearance"), Description("Gets or sets the Edge curve factor when the style is Balloon style!
Remarks

Used only by the BinaryToolTipStyle.BalloonType style; a standard tip has square corners. Larger values give a rounder, more pill-like balloon. Being a percentage, it looks the same at every display scale.

BorderColor

public Color BorderColor

Gets or sets the colour of the line round the tip.

Value
The outline colour. The default is Color.Brown.
Remarks

A balloon tip's outline, including its pointer, is two pixels wide; a standard tip's is one.

CustomWidth

public int CustomWidth

Gets or sets the width at which the tip's text wraps onto a new line.

Value
The wrap width in logical pixels. The default is 100; values below 100 are raised to 100.
Remarks

Used only while AutomaticMultiLineSupport is on. Line breaks in the text always start a new line.

Example
tip.AutomaticMultiLineSupport = true;
tip.CustomWidth = 260;   // wrap long hints at about 260 logical pixels

ShadowColor

public Color ShadowColor

Gets or sets the colour the tip's drop shadow is drawn in.

Value
The shadow colour. The default is Color.Black.
Designer category
Appearance"), Description("Gets or sets the colour the tip's drop shadow is drawn in"), DefaultValue(typeof(Color), "Black
Remarks

The shadow is drawn partly transparent and faded at its edge, so black darkens whatever is behind the tip on any theme. A light colour shows only over a background darker than itself.

See also

ShadowOffset

public Point ShadowOffset

Gets or sets how far the tip's drop shadow falls to the right and below the tip.

Value
The horizontal and vertical offset in logical pixels. The default is (7, 7).
Designer category
Appearance"), Description("Gets or sets the dropshadow position
Remarks

A larger offset makes the tip seem to float higher. The shadow's soft edge widens with the offset, between 2 and 24 pixels. Negative values cast the shadow up or to the left.

See also

TextForeColor

public Color TextForeColor

Gets or sets the colour of the tip's main text.

Value
The text colour. The default is SystemColors.WindowText.
See also

TitleForeColor

public Color TitleForeColor

Gets or sets the colour of the tip's title.

Value
The title colour. The default is SystemColors.WindowText.
See also

TitleWillBeBold

public bool TitleWillBeBold

Gets or sets whether the tip's title is bold.

Value
true for a bold title. The default is true.
Remarks

The title is drawn in the family of the system message box font at 8 points.

See also

TitleWillBeUnderlined

public bool TitleWillBeUnderlined

Gets or sets whether the tip's title is underlined.

Value
true to underline the title. The default is false.
Remarks

The title is drawn in the family of the system message box font at 8 points.

See also

ToolTipHideDelay

public int ToolTipHideDelay

Gets or sets how long a tip stays on screen if the pointer stays still.

Value
The time in milliseconds. The default is 5000.
Designer category
Behavior"), Description("Gets or sets the delay, in milliseconds, before when the tooltip will appear while the mouse is stationary over the target control"), DefaultValue(5000
Remarks

The tip closes sooner when the pointer moves, leaves the control or presses a button.

See also

ToolTipHoverDelay

public int ToolTipHoverDelay

Gets or sets how long the mouse pointer must rest on a control before its tip appears.

Value
The delay in milliseconds. The default is 500.
Designer category
Behavior"), Description("Gets or sets the delay, in milliseconds, before when the tooltip will appear while the mouse is stationary over the target control"), DefaultValue(500
Remarks

Moving the pointer starts the wait again.

See also

ToolTipReshowDelay

public int ToolTipReshowDelay

Gets or sets how long after one tip closes the pointer can move onto another control and see its tip at once, without waiting for ToolTipHoverDelay.

Value
The time in milliseconds. The default is 100.
Designer category
Behavior"), Description("Gets or sets the time, in milliseconds, when to reshow the tooltip as the mouse moves to another target control"), DefaultValue(100
Remarks

Lets a user run the pointer along a row of toolbar buttons and read each tip in turn.

ToolTipTextFont

public Font ToolTipTextFont

Gets or sets the font of the tip's main text.

Value
The font. When none has been set, the family of the system message box font at 8 points.
Designer category
Appearance"), Description("Gets or sets the font used to display the tooltip's text!"), Editor("FontEditor", typeof(System.Drawing.Design.UITypeEditor)
Remarks

The tip is sized to fit its text in this font each time it is shown. The title's font is set separately, with TitleWillBeBold and TitleWillBeUnderlined.

ToolTipTipStyle

public BinaryToolTipStyle ToolTipTipStyle

Gets or sets the shape of tips for controls that have not been given a style of their own.

Value
BinaryToolTipStyle.Standard for a rectangle, or BinaryToolTipStyle.BalloonType for a rounded balloon pointing at the mouse pointer. The default is BinaryToolTipStyle.Standard.
Designer category
Appearance"), Description("Gets or sets the style used to display the tooltip."), DefaultValue(BinaryToolTipStyle.Standard
Remarks

A style set for one control with SetBinaryToolTipStyle wins over this.

Methods

Dispose

protected override void Dispose(bool disposing)

Closes any open tip and releases the resources the component holds.

Parameters
disposing
true when called from Dispose(); false when called from a finaliser.

GetBinaryToolTipIcon

public Image GetBinaryToolTipIcon(object theAttachedObject)

Gets the picture shown in a control's tip.

Parameters
theAttachedObject
The control the tip belongs to.
Returns

The tip's copy of the picture, or null when there is none.

GetBinaryToolTipStyle

public BinaryToolTipStyle GetBinaryToolTipStyle(object theAttachedObject)

Gets the shape of a control's tip.

Parameters
theAttachedObject
The control the tip belongs to.
Returns

The style set for the control, or ToolTipTipStyle when none has been.

GetBinaryToolTipText

public string GetBinaryToolTipText(object theAttachedObject)

Gets the main text of a control's tip.

Parameters
theAttachedObject
The control the tip belongs to.
Returns

The text, or an empty string when the control has no tip.

See also

GetBinaryToolTipTitle

public string GetBinaryToolTipTitle(object theAttachedObject)

Gets the title of a control's tip.

Parameters
theAttachedObject
The control the tip belongs to.
Returns

The title, or an empty string when the control's tip has none.

SetBinaryToolTipIcon

public void SetBinaryToolTipIcon(object theAttachedObject, Image anImage)

Sets a small picture shown at the start of a control's tip, beside the title.

Parameters
theAttachedObject
The control the tip belongs to.
anImage
The picture, ideally 16 by 16 pixels, or null to remove it.
Remarks

The tip keeps its own copy, in which the colour of the top-left pixel is made see-through, so a picture on a plain background needs no transparency of its own. The picture's pixel size is taken as logical pixels and scaled with the display.

Example
tips.SetBinaryToolTipIcon(deleteButton, SystemIcons.Warning.ToBitmap());

SetBinaryToolTipStyle

public void SetBinaryToolTipStyle(object theAttachedObject, BinaryToolTipStyle theTipStyle)

Sets the shape of one control's tip, overriding ToolTipTipStyle.

Parameters
theAttachedObject
The control the tip belongs to.
theTipStyle
BinaryToolTipStyle.Standard for a rectangle, or BinaryToolTipStyle.BalloonType for a balloon pointing at the mouse pointer.

SetBinaryToolTipText

public void SetBinaryToolTipText(object theAttachedObject, string theTipText)

Sets the main text of a control's tip, and so gives the control a tip.

Parameters
theAttachedObject
The control the tip belongs to.
theTipText
The text. Long text wraps at CustomWidth; line breaks start a new line. An empty string removes the control's tip.
Remarks

Calling it again replaces the text. A control's title and icon are shown only while it has text.

Example
tips.SetBinaryToolTipText(postcodeBox, "Enter the postcode and press Find to fill in the address.");
See also

SetBinaryToolTipTitle

public void SetBinaryToolTipTitle(object theAttachedObject, string theTipText)

Sets the title shown above the text of a control's tip.

Parameters
theAttachedObject
The control the tip belongs to.
theTipText
The title. An empty string removes it.
Remarks

The title is drawn in TitleForeColor, bold unless TitleWillBeBold is off, beside the icon if there is one. A title alone does not give a control a tip; set its text as well.

See also