HypernovaDesktop Components · docs
Binarymission
WinForms › Alert Popup › AlertPopup

AlertPopup

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

A notification window that slides into a corner of the screen to tell the user something has happened – a new message, a finished export, a price alert – without taking the focus from what they are doing, and goes away again by itself.

public sealed partial class AlertPopup : Form

Inherits from / implements: Form

Remarks

What it is for

The alert is a borderless, top-most window with a shaped skin, in the manner of the Outlook and MSN Messenger desktop alerts. It is shown without activation, so typing carries on in the application while it is up. It carries a title, a line of body text, a title icon, an exit button and, optionally, a menu.

How to use it

Create one AlertPopup, keep it for the life of the form, and call one of the Show() overloads each time there is something to say. Showing it again while it is up starts it afresh with the new text. Show it on the UI thread; Hide may be called from any thread.

Each showing has three phases, each with its own duration: it grows out of the corner, stays for the visible time, and then goes away in the ControlDisappearingStyle. While the pointer is over it it stays (AlertPopupIsShownWhenMouseIsOver), and KeepShowingUntilHiddenDeterministically keeps it up until Hide is called.

Where it appears

In a corner of the primary screen's working area, clear of the taskbar – the bottom right unless PopupScreenCorner says otherwise – or at AlertPopupCustomLocation. The user can drag it by the strip along its top (AllowUserToDragDropPopupWindow).

Responding to the user

Clicks are reported, not acted on: PopupMessageTextClicked, PopupTitleTextClicked, PopupExitButtonClicked, PopupCustomImageClicked and ContextMenuShown. AboutToPopup, AboutToPlaySound, PopupExitButtonClicked and ContextMenuShown can each be cancelled.

Appearance

The built-in skins and their layout are in logical pixels and are scaled for the display.

Examples

An alert for incoming orders on a dispatch screen: clicking the text opens the order, and the exit button only hides the alert once it has been logged.

using System;
using System.Windows.Forms;
using Binarymission.WinForms.Controls.NotificationControls;

public partial class DispatchForm : Form
{
    private readonly AlertPopup orderAlert = new AlertPopup
    {
        AlertPopupStyle = AlertPopupStyle.Outlook,
        PopupAlertThemeColor = AlertPopupThemeColor.Silver,
        PopupScreenCorner = AlertPopupScreenCorner.BottomRight,
        ControlDisappearingStyle = DisappearingStyle.VanishOutWhileSlidingDown,
        CanClickTitle = true
    };

    private string latestOrderNumber;

    public DispatchForm()
    {
        InitializeComponent();

        orderAlert.PopupMessageTextClicked += (sender, e) => OpenOrder(latestOrderNumber);
        orderAlert.PopupTitleTextClicked += (sender, e) => OpenOrder(latestOrderNumber);
        orderAlert.PopupExitButtonClicked += (object sender, ref bool cancelNow) =>
            Console.WriteLine("Alert dismissed for " + latestOrderNumber);

        FormClosed += (sender, e) => orderAlert.Dispose();
    }

    private void OnOrderReceived(string orderNumber, string customer, decimal total)
    {
        latestOrderNumber = orderNumber;

        // Grow for 400 ms, stay for 6 seconds, go away over 600 ms.
        orderAlert.Show("New order " + orderNumber,
                        customer + " - " + total.ToString("C"),
                        400, 6000, 600);
    }

    private void OpenOrder(string orderNumber)
    {
        // Show the order in the application.
    }
}

Members at a glance

Constructors
AlertPopupInitialises an alert in the AlertPopupStyle.Outlook style and the AlertPopupThemeColor.Blue theme, for the bottom right-hand corner of the screen, with an exit button, a clickable body text and no sound.
Properties
AlertBodyTextGets or sets the message drawn in the body of the alert.
AlertNormalBodyTextColorGets or sets the colour of the body text.
AlertNormalBodyTextFontGets or sets the font of the body text.
AlertNormalTitleColorGets or sets the colour of the title.
AlertNormalTitleFontGets or sets the font of the title.
AlertOnHoverBodyTextColorGets or sets the colour of the body text while the pointer is over it, marking it as a link.
AlertOnHoverBodyTextFontGets or sets the font of the body text while the pointer is over it.
AlertOnHoverTitleColorGets or sets the colour of the title while the pointer is over it.
AlertOnHoverTitleFontGets or sets the font of the title while the pointer is over it.
AlertPopupCustomLocationGets or sets where the alert appears when it is shown by an overload that takes no location.
AlertPopupIsShownAgainWhenMousePointerIsOverGets or sets whether an alert that is going away comes back when the pointer moves onto it.
AlertPopupIsShownWhenMouseIsOverGets or sets whether the alert stays on screen past its visible time while the pointer is over it.
AlertPopupStyleGets or sets which built-in skin the alert wears: Outlook's or MSN Messenger's.
AlertTextSelectionRectangleColorGets or sets the colour of the dotted rectangle drawn round the body text while the pointer is over it.
AlertTitleTextGets or sets the title drawn at the top of the alert.
AllowUserToDragDropPopupWindowGets or sets whether the user can move the alert by dragging the strip along its top edge.
CanClickAlertTextGets or sets whether the body text reacts to the pointer and raises PopupMessageTextClicked when clicked.
CanClickExitButtonGets or sets whether the exit button responds to the pointer and to clicks.
CanClickTitleGets or sets whether the title reacts to the pointer and raises PopupTitleTextClicked when clicked.
ColorToUseForFillingContextMenuDropDownChevronRectangleWithSingleColorGets or sets the colour of the menu button's highlight when it is a single colour.
ContextMenuDropDownChevronColorGets or sets the colour of the chevron drawn on the menu button.
ContextMenuDropDownChevronRectangleBorderColorGets or sets the colour of the outline round the menu button while it is under the pointer or its menu is open.
ControlDisappearingStyleGets or sets how the alert goes away: fading out, sliding back into its edge of the screen, or both.
CustomAlertPopupWindowImageGets or sets a picture to show as the whole alert, in place of the built-in skin – a branded banner, a reminder card.
CustomAlertPopupWindowImageCanBeClickedGets or sets whether clicking an alert that shows CustomAlertPopupWindowImage raises PopupCustomImageClicked.
CustomAlertTextAreaGets or sets where the body text is drawn on the alert, in place of the style's own place for it.
CustomExitIconGets or sets an icon to draw as the exit button in place of the built-in one.
CustomTitleIconGets or sets the picture drawn as the alert's title icon, in place of the style's built-in one.
CustomTitleIconAlignmentGets or sets where on the alert the title icon is placed: one of nine positions.
CustomTitleIconLocationGets or sets exactly where the title icon's top-left corner is placed on the alert.
CustomTitleTextAreaGets or sets where the title is drawn on the alert, in place of the style's own place for it.
CustomUserWindowPaintSizeGets or sets the size of the surface you draw on when EnableCustomUserPaint is set – the size the alert window takes.
DisplayExitButtonGets or sets whether the alert has an exit button in its top right-hand corner.
DrawUsingColorTypeGets or sets whether custom colours fill the alert's body with one colour or a gradient.
DrawUsingCustomColorsGets or sets whether the body of the skin is filled with colours of your own instead of the theme's.
EnableCustomUserPaintGets or sets whether you draw the alert yourself, in a Control.Paint handler, instead of the built-in skin.
EndColorGets or sets the colour the custom gradient in the alert's body ends in.
EndColorToUseForFillingContextMenuDropDownChevronRectangleWithGradientColorsGets or sets the colour the menu button's highlight gradient ends in.
FillContextMenuDropDownChevronRectangleWithGradientColorsGets or sets whether the menu button's highlight is a gradient rather than a single colour.
GradientOrientationAngleGets or sets the direction of the gradient in the alert's body when it is drawn in custom colours.
GradientOrientationAngleToUseForFillingDropDownChevronRectangleGets or sets the direction of the colour gradient behind the menu button while it is under the pointer or its menu is open.
IsMouseCurrentlyDownGets whether a mouse button is held down on the alert.
OpacityGets or sets how opaque the alert window is, from 0 (invisible) to 1 (solid).
PlaySoundWhenPopupIsDisplayedGets or sets whether a sound is played each time the alert is shown.
PopupAlertThemeColorGets or sets the colour scheme of the built-in skin: blue, olive green or silver.
PopupScreenCornerGets or sets the corner of the screen's working area the alert appears in.
ShouldPerformAdvancedCleanupUponHideGets or sets whether the alert releases its animation timer each time it is hidden, rather than keeping it for the next showing.
ShowTextAreaRectangleGets or sets whether a dotted rectangle is drawn round the body text while the pointer is over it.
SoundPlayBackFileGets or sets the full path of the sound file played when the alert is shown.
SpecificColorGets or sets the single colour the alert's body is filled with when it is drawn in custom colours.
StartColorGets or sets the colour the custom gradient in the alert's body starts from.
StartColorToUseForFillingContextMenuDropDownChevronRectangleWithGradientColorsGets or sets the colour the menu button's highlight gradient starts from.
StretchTitleIconToCoverTheEntireControlAreaGets or sets whether the title icon is stretched over the whole alert, as a background picture under the text.
UseCustomAlertPopupWindowImageGets or sets whether the alert shows CustomAlertPopupWindowImage instead of its built-in skin.
Methods
CleanUpUponContextMenuItemClickedTells the alert that its menu has closed, and starts it going away.
DisposeReleases the timer that drives the animation and the skin bitmaps the alert made for itself.
HideTakes the alert off the screen at once, without its going-away animation.
KeepShowingUntilHiddenDeterministicallyKeeps the alert on screen until Hide is called, instead of letting it go away after its visible time.
OnClickRaises Control.Click and clears the alert's open-menu state.
OnMouseDownShows the exit button pressed, and starts a drag when the press is on the strip along the top.
OnMouseEnterNotes that the pointer is over the alert, which keeps it on screen while AlertPopupIsShownWhenMouseIsOver is set.
OnMouseLeaveNotes that the pointer has left the alert, returning the title, text and buttons to their resting look.
OnMouseMoveLights up the part of the alert under the pointer – exit button, menu button, title or text – and moves the alert while it is being dragged.
OnMouseUpCompletes a click on the part of the alert under the pointer, raising the event for that part.
OnPaintRaises the Control.Paint event while EnableCustomUserPaint is set, and does nothing otherwise.
OnPaintBackgroundDraws the whole alert: skin, exit and menu buttons, title icon, title and body text.
ShowShows the alert with no title and no body text, with the standard timings.
ShowShows the alert with this title and body text, with the standard timings.
ShowShows the alert with this title and body text, taking the times you give for each phase.
ShowShows the alert with this title and body text, for the times you give, at a place of your choosing.
Events
AboutToPlaySoundOccurs each time the alert is shown, after AboutToPopup, before its sound would play.
AboutToPopupOccurs each time a Show method is called, before the alert appears.
ContextMenuShownOccurs when the user clicks the menu button, before the menu opens.
PopupCustomImageClickedOccurs when the user clicks an alert that is showing CustomAlertPopupWindowImage, anywhere but on the exit button and the drag strip along the top.
PopupExitButtonClickedOccurs when the user clicks the exit button, before the alert starts to go away.
PopupMessageTextClickedOccurs when the user clicks the body text, while CanClickAlertText is set.
PopupTitleTextClickedOccurs when the user clicks the title, while CanClickTitle is set.

Constructors

AlertPopup

public AlertPopup()

Initialises an alert in the AlertPopupStyle.Outlook style and the AlertPopupThemeColor.Blue theme, for the bottom right-hand corner of the screen, with an exit button, a clickable body text and no sound.

Remarks

The window is created here but stays hidden until a Show method is called.

Properties

AlertBodyText

public string AlertBodyText

Gets or sets the message drawn in the body of the alert.

Value
The default is null: no message.
Remarks

The message is centred and is not word-wrapped; one too long for the body ends in an ellipsis.

Every Show method sets it. Setting it while the alert is on screen redraws the alert – to count down a reconnection, say – but the area that responds to the pointer stays measured for the message it was shown with.

AlertNormalBodyTextColor

public Color AlertNormalBodyTextColor

Gets or sets the colour of the body text.

Value
The default is black.
Designer category
Color properties
See also

AlertNormalBodyTextFont

public Font AlertNormalBodyTextFont

Gets or sets the font of the body text.

Value
The default is the Windows message box font family at 8.25 points, regular.
See also

AlertNormalTitleColor

public Color AlertNormalTitleColor

Gets or sets the colour of the title.

Value
The default is pure red, Color.FromArgb(255, 0, 0).
Designer category
Color properties
See also

AlertNormalTitleFont

public Font AlertNormalTitleFont

Gets or sets the font of the title.

Value
The default is the Windows message box font family at 9 points, regular.
See also

AlertOnHoverBodyTextColor

public Color AlertOnHoverBodyTextColor

Gets or sets the colour of the body text while the pointer is over it, marking it as a link.

Value
The default is dark blue, Color.FromArgb(0, 0, 156).
Designer category
Color properties
Remarks

Used only while CanClickAlertText is set.

AlertOnHoverBodyTextFont

public Font AlertOnHoverBodyTextFont

Gets or sets the font of the body text while the pointer is over it.

Value
The default is the Windows message box font family at 8.25 points, regular – the same as AlertNormalBodyTextFont.
Remarks

The text's clickable area is measured in this font.

AlertOnHoverTitleColor

public Color AlertOnHoverTitleColor

Gets or sets the colour of the title while the pointer is over it.

Value
The default is pure red, Color.FromArgb(255, 0, 0), the same as AlertNormalTitleColor.
Designer category
Color properties
Remarks

Used only while CanClickTitle is set.

AlertOnHoverTitleFont

public Font AlertOnHoverTitleFont

Gets or sets the font of the title while the pointer is over it.

Value
The default is the Windows message box font family at 9 points, bold.
Remarks

The title's clickable area is measured in this font, so it covers the title in either font.

AlertPopupCustomLocation

public Point AlertPopupCustomLocation

Gets or sets where the alert appears when it is shown by an overload that takes no location.

Value
A point in screen coordinates. The default is (0, 0): the corner given by PopupScreenCorner.
Remarks

With a bottom corner set in PopupScreenCorner the alert grows upwards from this point, so it is where the alert's lower-left corner comes to rest; with a top corner it is the upper-left corner.

See also

AlertPopupIsShownAgainWhenMousePointerIsOver

public bool AlertPopupIsShownAgainWhenMousePointerIsOver

Gets or sets whether an alert that is going away comes back when the pointer moves onto it.

Value
true to bring it back. The default is false.
Remarks

An alert closed with its exit button does not come back.

AlertPopupIsShownWhenMouseIsOver

public bool AlertPopupIsShownWhenMouseIsOver

Gets or sets whether the alert stays on screen past its visible time while the pointer is over it.

Value
true to keep it while the pointer rests anywhere on it. The default is true.
Remarks

The alert starts to go away once the pointer leaves. That gives the user time to read and click.

See also

AlertPopupStyle

public AlertPopupStyle AlertPopupStyle

Gets or sets which built-in skin the alert wears: Outlook's or MSN Messenger's.

Value
The default is AlertPopupStyle.Outlook.
Designer category
Popup Style properties
Remarks

The style sets the alert's size and shape, and where the title, text, icon and exit button go. PopupAlertThemeColor picks the colours of either skin. Only the Outlook style has a menu button.

AlertTextSelectionRectangleColor

public Color AlertTextSelectionRectangleColor

Gets or sets the colour of the dotted rectangle drawn round the body text while the pointer is over it.

Value
The default is SystemColors.Highlight.
Designer category
Color properties
Remarks

Drawn only while ShowTextAreaRectangle and CanClickAlertText are set.

AlertTitleText

public string AlertTitleText

Gets or sets the title drawn at the top of the alert.

Value
The default is null: no title.
Remarks

Every Show method sets it. Setting it while the alert is on screen redraws the alert, but the area that responds to the pointer stays measured for the title it was shown with.

AllowUserToDragDropPopupWindow

public bool AllowUserToDragDropPopupWindow

Gets or sets whether the user can move the alert by dragging the strip along its top edge.

Value
true to allow it. The default is true.
Remarks

The strip is the top 8 logical pixels of the alert; the pointer shows the move cursor over it. A moved alert goes away from where it was left.

CanClickAlertText

public bool CanClickAlertText

Gets or sets whether the body text reacts to the pointer and raises PopupMessageTextClicked when clicked.

Value
true to make the text clickable. The default is true.
Remarks

Under the pointer the text is drawn in AlertOnHoverBodyTextColor and AlertOnHoverBodyTextFont, inside a dotted rectangle while ShowTextAreaRectangle is set.

CanClickExitButton

public bool CanClickExitButton

Gets or sets whether the exit button responds to the pointer and to clicks.

Value
true to let the user close the alert with it. The default is true.
Remarks

Set it to false to leave the button on show but inert. To remove it, set DisplayExitButton to false.

CanClickTitle

public bool CanClickTitle

Gets or sets whether the title reacts to the pointer and raises PopupTitleTextClicked when clicked.

Value
true to make the title clickable. The default is false.
Remarks

While it is clickable the title is drawn in AlertOnHoverTitleColor and AlertOnHoverTitleFont under the pointer, which shows a hand.

ColorToUseForFillingContextMenuDropDownChevronRectangleWithSingleColor

public Color ColorToUseForFillingContextMenuDropDownChevronRectangleWithSingleColor

Gets or sets the colour of the menu button's highlight when it is a single colour.

Value
The default is SystemColors.Window. Used while FillContextMenuDropDownChevronRectangleWithGradientColors is false.
Designer category
Color properties

ContextMenuDropDownChevronColor

public Color ContextMenuDropDownChevronColor

Gets or sets the colour of the chevron drawn on the menu button.

Value
The default is SystemColors.WindowText. Color.Empty draws the chevron in its built-in colours.
Designer category
Color properties
Remarks

The menu button is drawn only while Control.ContextMenu is set, in the AlertPopupStyle.Outlook style, without a CustomAlertPopupWindowImage.

See also

ContextMenuDropDownChevronRectangleBorderColor

public Color ContextMenuDropDownChevronRectangleBorderColor

Gets or sets the colour of the outline round the menu button while it is under the pointer or its menu is open.

Value
The default is SystemColors.Highlight.
Designer category
Color properties

ControlDisappearingStyle

public DisappearingStyle ControlDisappearingStyle

Gets or sets how the alert goes away: fading out, sliding back into its edge of the screen, or both.

Value
The default is DisappearingStyle.VanishOutWhileSlidingDown.
Designer category
Popup Style properties
Remarks

The styles that fade out also fade the alert in as it appears; DisappearingStyle.SlideDown shows it solid from the start.

Setting the property also sets the window's Opacity (to 1 when the previous style was DisappearingStyle.SlideDown, otherwise to 0), so set it while the alert is not on screen.

CustomAlertPopupWindowImage

public Image CustomAlertPopupWindowImage

Gets or sets a picture to show as the whole alert, in place of the built-in skin – a branded banner, a reminder card.

Value
A Bitmap. The default is null. Shown only while UseCustomAlertPopupWindowImage is set.
Remarks

The alert takes the picture's size, scaled for the display, and its shape: pixels of pure magenta (red 255, green 0, blue 255) are cut out of the window, so a picture with rounded corners painted on magenta gives a round-cornered alert.

While a picture is shown the alert draws no title, text, icon or menu button over it – put the message in the picture – but it does draw the exit button in the top right-hand corner. Clicks on the picture raise PopupCustomImageClicked. The image remains yours: the alert does not dispose it.

Example
alert.CustomAlertPopupWindowImage = new Bitmap(@"C:\ProgramData\Contoso\renewal-banner.png");
alert.UseCustomAlertPopupWindowImage = true;
alert.PopupCustomImageClicked += (sender, e) => OpenRenewalPage();
alert.Show();

CustomAlertPopupWindowImageCanBeClicked

public bool CustomAlertPopupWindowImageCanBeClicked

Gets or sets whether clicking an alert that shows CustomAlertPopupWindowImage raises PopupCustomImageClicked.

Value
true to raise the event. The default is true.
Remarks

The pointer shows a hand over such an alert either way.

CustomAlertTextArea

public Rectangle CustomAlertTextArea

Gets or sets where the body text is drawn on the alert, in place of the style's own place for it.

Value
A rectangle measured from the alert's top-left corner. The default is Rectangle.Empty: the style's own text area.
Remarks

The text is centred in the area and is not word-wrapped; text too long for it ends in an ellipsis. The clickable area is worked out when the alert is shown, so set this before calling a Show method.

The rectangle is used as it is, in device pixels, without scaling for the display – unlike the built-in areas, which are scaled.

CustomExitIcon

public Icon CustomExitIcon

Gets or sets an icon to draw as the exit button in place of the built-in one.

Value
The default is null: the built-in button, which lights up under the pointer and shows when it is pressed.
Remarks

The icon is drawn 16 logical pixels square, whatever its own size, and does not change under the pointer.

CustomTitleIcon

public Image CustomTitleIcon

Gets or sets the picture drawn as the alert's title icon, in place of the style's built-in one.

Value
The default is null: the built-in icon of the AlertPopupStyle.
Remarks

The icon is drawn at its own size up to 32 by 32 logical pixels; a larger picture is drawn at 32 by 32. It is placed by CustomTitleIconAlignment or CustomTitleIconLocation, or stretched over the alert by StretchTitleIconToCoverTheEntireControlArea.

It is not drawn while a CustomAlertPopupWindowImage is shown. The image remains yours: the alert does not dispose it.

CustomTitleIconAlignment

public ContentAlignment CustomTitleIconAlignment

Gets or sets where on the alert the title icon is placed: one of nine positions.

Value
The default is ContentAlignment.TopLeft.
Remarks

The icon is kept 8 logical pixels in from the edges; at ContentAlignment.TopRight it moves left of the exit button. Setting the alignment replaces any CustomTitleIconLocation.

CustomTitleIconLocation

public Point CustomTitleIconLocation

Gets or sets exactly where the title icon's top-left corner is placed on the alert.

Value
In logical pixels from the alert's top-left corner. The default is Point.Empty: the icon is placed by CustomTitleIconAlignment.
Remarks

A location set here wins over the alignment until CustomTitleIconAlignment is set again or this is set back to Point.Empty.

CustomTitleTextArea

public Rectangle CustomTitleTextArea

Gets or sets where the title is drawn on the alert, in place of the style's own place for it.

Value
A rectangle measured from the alert's top-left corner. The default is Rectangle.Empty: the style's own title area.
Remarks

The title is drawn on one line, left-aligned and centred vertically, and is cut short with an ellipsis if it does not fit. The clickable area is worked out when the alert is shown, so set this before calling a Show method.

The rectangle is used as it is, in device pixels, without scaling for the display – unlike the built-in areas, which are scaled.

See also

CustomUserWindowPaintSize

public Size CustomUserWindowPaintSize

Gets or sets the size of the surface you draw on when EnableCustomUserPaint is set – the size the alert window takes.

Value
In logical pixels. The default is 200 by 200.
Remarks

Setting it replaces CustomAlertPopupWindowImage with a blank bitmap of this size, whether or not custom painting is on, so set it before any image of your own. Set it before EnableCustomUserPaint, or set EnableCustomUserPaint again afterwards.

On a display scaled above 100% the window comes out larger than this size times the scale: the blank surface is made at the display's scale and is then scaled again as the window's skin.

Example
alert.CustomUserWindowPaintSize = new Size(320, 140);
alert.EnableCustomUserPaint = true;
alert.Paint += (sender, e) =>
{
    e.Graphics.Clear(Color.White);
    TextRenderer.DrawText(e.Graphics, "Backup finished: 1,284 files", alert.Font,
                          new Point(12, 40), Color.DarkGreen);
};
alert.Controls.Add(new Button { Text = "View log", Location = new Point(12, 90), Width = 100 });

DisplayExitButton

public bool DisplayExitButton

Gets or sets whether the alert has an exit button in its top right-hand corner.

Value
true to show it. The default is true.
Designer category
Popup Style properties
Remarks

Without it the alert goes away only by itself or by Hide.

See also

DrawUsingColorType

public CustomColorType DrawUsingColorType

Gets or sets whether custom colours fill the alert's body with one colour or a gradient.

Value
The default is CustomColorType.GradientColors.
Designer category
Popup Style properties
Remarks

Used while DrawUsingCustomColors is set.

DrawUsingCustomColors

public bool DrawUsingCustomColors

Gets or sets whether the body of the skin is filled with colours of your own instead of the theme's.

Value
true to use your colours. The default is false.
Designer category
Popup Style properties
Remarks

The skin keeps its outline and shape; inside it the alert is filled with SpecificColor or with a gradient from StartColor to EndColor, as DrawUsingColorType says.

Example
alert.DrawUsingCustomColors = true;
alert.DrawUsingColorType = CustomColorType.GradientColors;
alert.StartColor = Color.FromArgb(255, 243, 205);   // amber, for a warning
alert.EndColor = Color.White;
alert.GradientOrientationAngle = 90f;

EnableCustomUserPaint

public bool EnableCustomUserPaint

Gets or sets whether you draw the alert yourself, in a Control.Paint handler, instead of the built-in skin.

Value
true to draw it yourself. The default is false.
Remarks

Setting it to true gives the alert a blank, rectangular surface of CustomUserWindowPaintSize and sets UseCustomAlertPopupWindowImage. From then on the alert draws nothing of its own – no skin, text, icon or buttons – and raises Control.Paint, Control.MouseDown, Control.MouseMove, Control.MouseEnter and Control.MouseLeave instead of its click events. It still animates, and can still be dragged by its top strip. You can add child controls to it like any form.

Setting it back to false does not clear UseCustomAlertPopupWindowImage.

See also

EndColor

public Color EndColor

Gets or sets the colour the custom gradient in the alert's body ends in.

Value
The default is Color.White.
Designer category
Color properties
See also

EndColorToUseForFillingContextMenuDropDownChevronRectangleWithGradientColors

public Color EndColorToUseForFillingContextMenuDropDownChevronRectangleWithGradientColors

Gets or sets the colour the menu button's highlight gradient ends in.

Value
The default is Color.White.
Designer category
Color properties
See also

FillContextMenuDropDownChevronRectangleWithGradientColors

public bool FillContextMenuDropDownChevronRectangleWithGradientColors

Gets or sets whether the menu button's highlight is a gradient rather than a single colour.

Value
true for a gradient from StartColorToUseForFillingContextMenuDropDownChevronRectangleWithGradientColors to EndColorToUseForFillingContextMenuDropDownChevronRectangleWithGradientColors; false for ColorToUseForFillingContextMenuDropDownChevronRectangleWithSingleColor. The default is true.
Designer category
Color properties
Remarks

The highlight is drawn while the button is under the pointer or its menu is open. The menu button is drawn only while Control.ContextMenu is set, in the AlertPopupStyle.Outlook style, without a CustomAlertPopupWindowImage.

GradientOrientationAngle

public float GradientOrientationAngle

Gets or sets the direction of the gradient in the alert's body when it is drawn in custom colours.

Value
In degrees, clockwise from left to right. The default is 90: StartColor at the top, EndColor at the bottom.
Designer category
Color properties

GradientOrientationAngleToUseForFillingDropDownChevronRectangle

public float GradientOrientationAngleToUseForFillingDropDownChevronRectangle

Gets or sets the direction of the colour gradient behind the menu button while it is under the pointer or its menu is open.

Value
In degrees, clockwise from left to right. The default is 90: from the top down.
Designer category
Color properties
Remarks

Used while FillContextMenuDropDownChevronRectangleWithGradientColors is set. The menu button is drawn only while Control.ContextMenu is set, in the AlertPopupStyle.Outlook style, without a CustomAlertPopupWindowImage.

IsMouseCurrentlyDown

public bool IsMouseCurrentlyDown

Gets whether a mouse button is held down on the alert.

Value
true from a button press on the alert until its release.

Opacity

public new double Opacity

Gets or sets how opaque the alert window is, from 0 (invisible) to 1 (solid).

Value
Between 0.0 and 1.0. The alert sets it itself as it fades in and out.
Remarks

This property hides Opacity so that it can be set from any thread – off the UI thread the change is passed to the UI thread. Setting it yourself is overridden by the next step of the animation.

PlaySoundWhenPopupIsDisplayed

public bool PlaySoundWhenPopupIsDisplayed

Gets or sets whether a sound is played each time the alert is shown.

Value
true to play SoundPlayBackFile. The default is false.
Remarks

The sound plays in the background as the alert starts to appear. Handle AboutToPlaySound to silence a particular showing.

PopupAlertThemeColor

public AlertPopupThemeColor PopupAlertThemeColor

Gets or sets the colour scheme of the built-in skin: blue, olive green or silver.

Value
The default is AlertPopupThemeColor.Blue.
Designer category
Color properties
Remarks

Applies to both AlertPopupStyle skins. Not used while DrawUsingCustomColors fills the skin, or a CustomAlertPopupWindowImage replaces it.

PopupScreenCorner

public AlertPopupScreenCorner PopupScreenCorner

Gets or sets the corner of the screen's working area the alert appears in.

Value
The default is AlertPopupScreenCorner.BottomRight.
Default
AlertPopupScreenCorner.BottomRight
Designer category
Popup Style properties
Remarks

The screen is the one the application's active window is on, or the one under the pointer when none of its windows is active.

The corner also sets which way the alert travels: from a bottom corner it grows upwards and slides back down; from a top corner it grows downwards and draws back up. It sits a scroll bar's width in from the side of the working area, so it clears the taskbar.

The corner is not used when a location is given to the Show call or set in AlertPopupCustomLocation; it still sets the direction of travel.

ShouldPerformAdvancedCleanupUponHide

public bool ShouldPerformAdvancedCleanupUponHide

Gets or sets whether the alert releases its animation timer each time it is hidden, rather than keeping it for the next showing.

Value
true to release it on every hide. The default is false.
Remarks

The next Show creates a new timer, so the alert can go on being used. Worth setting for an alert that is shown rarely in a long-running application.

ShowTextAreaRectangle

public bool ShowTextAreaRectangle

Gets or sets whether a dotted rectangle is drawn round the body text while the pointer is over it.

Value
true to draw it. The default is true.
Remarks

It marks the text as a link. Drawn in AlertTextSelectionRectangleColor, and only while CanClickAlertText is set.

SoundPlayBackFile

public string SoundPlayBackFile

Gets or sets the full path of the sound file played when the alert is shown.

Value
The path of a .wav file. The default is an empty string.
Remarks

Played only while PlaySoundWhenPopupIsDisplayed is set. Only wave files are supported.

Example
alert.SoundPlayBackFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows),
                                       @"Media\Windows Notify Messaging.wav");
alert.PlaySoundWhenPopupIsDisplayed = true;

SpecificColor

public Color SpecificColor

Gets or sets the single colour the alert's body is filled with when it is drawn in custom colours.

Value
The default is Color.LightSeaGreen.
Designer category
Color properties
Remarks

Used while DrawUsingCustomColors is set and DrawUsingColorType is CustomColorType.SpecificColor. Takes effect the next time the alert is drawn.

StartColor

public Color StartColor

Gets or sets the colour the custom gradient in the alert's body starts from.

Value
The default is Color.LightGreen.
Designer category
Color properties
Remarks

Used while DrawUsingCustomColors is set and DrawUsingColorType is CustomColorType.GradientColors. Takes effect the next time the alert is drawn.

StartColorToUseForFillingContextMenuDropDownChevronRectangleWithGradientColors

public Color StartColorToUseForFillingContextMenuDropDownChevronRectangleWithGradientColors

Gets or sets the colour the menu button's highlight gradient starts from.

Value
The default is Color.Orange.
Designer category
Color properties
See also

StretchTitleIconToCoverTheEntireControlArea

public bool StretchTitleIconToCoverTheEntireControlArea

Gets or sets whether the title icon is stretched over the whole alert, as a background picture under the text.

Value
true to stretch it. The default is false.
Remarks

While it is set, CustomTitleIconAlignment and CustomTitleIconLocation are not used. The icon is CustomTitleIcon, or the built-in one when that is not set.

UseCustomAlertPopupWindowImage

public bool UseCustomAlertPopupWindowImage

Gets or sets whether the alert shows CustomAlertPopupWindowImage instead of its built-in skin.

Value
true to show the picture. The default is false. Has no effect while CustomAlertPopupWindowImage is null.
See also

Methods

CleanUpUponContextMenuItemClicked

public void CleanUpUponContextMenuItemClicked()

Tells the alert that its menu has closed, and starts it going away.

Remarks

While its menu is open the alert stays on screen. Call this as the last line of each menu item's MenuItem.Click handler, so the alert goes away in its ControlDisappearingStyle once the user has made a choice.

Example
var snooze = new MenuItem("Remind me in 10 minutes");
snooze.Click += (sender, e) =>
{
    reminders.Snooze(currentReminder, TimeSpan.FromMinutes(10));
    alert.CleanUpUponContextMenuItemClicked();
};

alert.ContextMenu = new ContextMenu();
alert.ContextMenu.MenuItems.Add(snooze);
See also

Dispose

protected override void Dispose(bool disposing)

Releases the timer that drives the animation and the skin bitmaps the alert made for itself.

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

Images you supplied – CustomAlertPopupWindowImage, CustomTitleIcon, CustomExitIcon – are not disposed; they remain yours.

Hide

public new void Hide()

Takes the alert off the screen at once, without its going-away animation.

Remarks

Safe to call from any thread: off the UI thread the call is passed to the UI thread and returns before the alert has gone. It ends KeepShowingUntilHiddenDeterministically, and does nothing when the alert is not showing.

To let the alert go away in its ControlDisappearingStyle instead, leave it to its timer.

KeepShowingUntilHiddenDeterministically

public void KeepShowingUntilHiddenDeterministically()

Keeps the alert on screen until Hide is called, instead of letting it go away after its visible time.

Remarks

Call it after the Show method, because every Show starts with the alert's own timing again. Called while the alert is going away, it brings it back. Use it for news the user must acknowledge – a failed payment run, a lost connection.

Example
alert.Show("Connection lost", "Trying to reconnect to the order server...");
alert.KeepShowingUntilHiddenDeterministically();

// Later, once the connection is back:
alert.Hide();

OnClick

protected override void OnClick(EventArgs e)

Raises Control.Click and clears the alert's open-menu state.

Parameters
e
The event data.
Remarks

Control.Click is raised for a click anywhere on the alert. To act on a click on one part, handle PopupMessageTextClicked, PopupTitleTextClicked or PopupCustomImageClicked.

OnMouseDown

protected override void OnMouseDown(MouseEventArgs theEventArgs)

Shows the exit button pressed, and starts a drag when the press is on the strip along the top.

Parameters
theEventArgs
The event data.
Remarks

The Control.MouseDown event is raised only while EnableCustomUserPaint is set.

OnMouseEnter

protected override void OnMouseEnter(EventArgs theEventArgs)

Notes that the pointer is over the alert, which keeps it on screen while AlertPopupIsShownWhenMouseIsOver is set.

Parameters
theEventArgs
The event data.
Remarks

The Control.MouseEnter event is raised only while EnableCustomUserPaint is set.

OnMouseLeave

protected override void OnMouseLeave(EventArgs theEventArgs)

Notes that the pointer has left the alert, returning the title, text and buttons to their resting look.

Parameters
theEventArgs
The event data.
Remarks

The Control.MouseLeave event is raised only while EnableCustomUserPaint is set.

OnMouseMove

protected override void OnMouseMove(MouseEventArgs theEventArgs)

Lights up the part of the alert under the pointer – exit button, menu button, title or text – and moves the alert while it is being dragged.

Parameters
theEventArgs
The event data.
Remarks

The Control.MouseMove event is raised only while EnableCustomUserPaint is set.

OnMouseUp

protected override void OnMouseUp(MouseEventArgs theEventArgs)

Completes a click on the part of the alert under the pointer, raising the event for that part.

Parameters
theEventArgs
The event data.
Remarks

Raises ContextMenuShown and opens the menu, PopupExitButtonClicked and starts the alert going away, PopupTitleTextClicked, PopupMessageTextClicked or PopupCustomImageClicked.

While EnableCustomUserPaint is set none of these is raised. The Control.MouseUp event is raised in both modes, before the click is handled.

OnPaint

protected override void OnPaint(PaintEventArgs pe)

Raises the Control.Paint event while EnableCustomUserPaint is set, and does nothing otherwise.

Parameters
pe
The surface to draw on.
Remarks

The built-in drawing is done in OnPaintBackground.

OnPaintBackground

protected override void OnPaintBackground(PaintEventArgs theEventArgs)

Draws the whole alert: skin, exit and menu buttons, title icon, title and body text.

Parameters
theEventArgs
The surface to draw on.
Remarks

The alert is drawn off screen and copied in one step, so it does not flicker. While EnableCustomUserPaint is set nothing is drawn here, and the surface is yours.

Show

public new void Show()

Shows the alert with no title and no body text, with the standard timings.

Remarks

The alert grows into place over half a second, stays for three seconds and goes away over half a second, in a corner of the screen (PopupScreenCorner) or at AlertPopupCustomLocation when that is set.

It clears AlertTitleText and AlertBodyText, so it suits an alert that carries its message in a picture (CustomAlertPopupWindowImage) or is drawn by you (EnableCustomUserPaint). This overload hides Show(): the alert is never activated and never takes the focus.

See also

Show

public void Show(string theAlertTitle, string theBodyText)

Shows the alert with this title and body text, with the standard timings.

Parameters
theAlertTitle
The title, drawn on one line at the top. null or empty draws no title.
theBodyText
The message, drawn centred in the body. null or empty draws no message.
Remarks

The alert grows into place over half a second, stays for three seconds and goes away over half a second, in a corner of the screen (PopupScreenCorner) or at AlertPopupCustomLocation when that is set.

Example
alert.Show("Export finished", "Orders-October.xlsx was saved to Documents");

Show

public void Show(string theAlertTitle, string theBodyText, int theAnimationDuration, int theVisibilityDuration, int theAnimationHidingDuration)

Shows the alert with this title and body text, taking the times you give for each phase.

Parameters
theAlertTitle
The title, drawn on one line at the top. null or empty draws no title.
theBodyText
The message, drawn centred in the body. null or empty draws no message.
theAnimationDuration
How long the alert takes to grow into place, in milliseconds. 10 or less shows it at once.
theVisibilityDuration
How long it stays fully shown before it starts to go away, in milliseconds.
theAnimationHidingDuration
How long it takes to go away, in milliseconds.
Remarks

The alert appears in a corner of the screen (PopupScreenCorner) or at AlertPopupCustomLocation when that is set.

See also

Show

public void Show(string theAlertTitle, string theBodyText, int theAnimationDuration, int theVisibilityDuration, int theAnimationHidingDuration, Point customLocationToShowThePopup)

Shows the alert with this title and body text, for the times you give, at a place of your choosing.

Parameters
theAlertTitle
The title, drawn on one line at the top. null or empty draws no title.
theBodyText
The message, drawn centred in the body. null or empty draws no message.
theAnimationDuration
How long the alert takes to grow into place, in milliseconds. 10 or less shows it at once.
theVisibilityDuration
How long it stays fully shown before it starts to go away, in milliseconds. The pointer resting on the alert extends it while AlertPopupIsShownWhenMouseIsOver is set.
theAnimationHidingDuration
How long it takes to go away, in milliseconds.
customLocationToShowThePopup
A point on the screen, in screen coordinates, or (0, 0) for the corner given by PopupScreenCorner. With a bottom corner the alert grows upwards from this point, so it is where its lower-left corner comes to rest; with a top corner it is the upper-left corner.
Remarks

Every other overload comes here. In order, it takes down an alert already on screen, raises AboutToPopup (and stops if that is cancelled), raises AboutToPlaySound and plays SoundPlayBackFile if PlaySoundWhenPopupIsDisplayed is set, measures the text, and starts the alert growing – fading in as well unless ControlDisappearingStyle is DisappearingStyle.SlideDown.

The animations move in small steps on a timer, so their durations are approximate. Call this method on the UI thread.

Example
// Over the status bar of the main window rather than in a corner of the screen.
Point anchor = PointToScreen(new Point(ClientSize.Width - 340, statusStrip.Top));
alert.Show("Sync complete", "214 contacts updated", 300, 5000, 800, anchor);

Events

AboutToPlaySound

public event AboutToPlaySoundHandler AboutToPlaySound

Occurs each time the alert is shown, after AboutToPopup, before its sound would play.

Remarks

Raised whether or not PlaySoundWhenPopupIsDisplayed is set. Set the handler's cancelNow argument to true to show the alert silently this time.

AboutToPopup

public event AboutToPopupHandler AboutToPopup

Occurs each time a Show method is called, before the alert appears.

Remarks

Set the handler's cancelNow argument to true to stop it appearing – while the user is presenting, say. An alert that was already on screen has been taken down by then.

Example
alert.AboutToPopup += (object sender, ref bool cancelNow) =>
{
    cancelNow = doNotDisturbCheckBox.Checked;
};

ContextMenuShown

public event ContextMenuShowHandler ContextMenuShown

Occurs when the user clicks the menu button, before the menu opens.

Remarks

The menu button – a small chevron beside the exit button – is drawn when the alert's Control.ContextMenu is set, in the AlertPopupStyle.Outlook style and without a CustomAlertPopupWindowImage. The menu opens below the button if it has any items.

Set the handler's cancelContextMenuDisplayNow argument to true to keep the menu closed, or to fill it with items for the current alert first.

See also

PopupCustomImageClicked

public event PopupCustomImageClickedHandler PopupCustomImageClicked

Occurs when the user clicks an alert that is showing CustomAlertPopupWindowImage, anywhere but on the exit button and the drag strip along the top.

Remarks

Raised only while UseCustomAlertPopupWindowImage and CustomAlertPopupWindowImageCanBeClicked are both set. The event data carries the mouse position, so a picture with several areas on it can tell which was clicked.

Example
alert.PopupCustomImageClicked += (sender, e) =>
{
    // The left half of the banner opens the invoice, the right half snoozes the reminder.
    if (e.MouseEventArgs.X < alert.Width / 2) OpenInvoice(); else Snooze();
};

PopupExitButtonClicked

public event ExitButtonClickHandler PopupExitButtonClicked

Occurs when the user clicks the exit button, before the alert starts to go away.

Remarks

Set the handler's cancelNow argument to true to keep the alert on screen. Otherwise it goes away in its ControlDisappearingStyle, and does not come back under the pointer.

See also

PopupMessageTextClicked

public event EventHandler PopupMessageTextClicked

Occurs when the user clicks the body text, while CanClickAlertText is set.

Remarks

Only the text itself is clickable, not the empty space round it. The alert stays on screen; call Hide from the handler to close it at once.

Example
alert.PopupMessageTextClicked += (sender, e) =>
{
    alert.Hide();
    ordersGrid.Focus();
};

PopupTitleTextClicked

public event EventHandler PopupTitleTextClicked

Occurs when the user clicks the title, while CanClickTitle is set.

Remarks

The alert stays on screen; call Hide from the handler to close it at once.