AlertPopup
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
AlertPopupStyleandPopupAlertThemeColorchoose the built-in skin;DrawUsingCustomColorsfills it with colours of your own.CustomAlertPopupWindowImagereplaces the skin with a picture of your own, whose shape the window takes.EnableCustomUserPainthands the whole surface to yourControl.Painthandler and child controls.
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 | |
|---|---|
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. |
| Properties | |
AlertBodyText | Gets or sets the message drawn in the body of the alert. |
AlertNormalBodyTextColor | Gets or sets the colour of the body text. |
AlertNormalBodyTextFont | Gets or sets the font of the body text. |
AlertNormalTitleColor | Gets or sets the colour of the title. |
AlertNormalTitleFont | Gets or sets the font of the title. |
AlertOnHoverBodyTextColor | Gets or sets the colour of the body text while the pointer is over it, marking it as a link. |
AlertOnHoverBodyTextFont | Gets or sets the font of the body text while the pointer is over it. |
AlertOnHoverTitleColor | Gets or sets the colour of the title while the pointer is over it. |
AlertOnHoverTitleFont | Gets or sets the font of the title while the pointer is over it. |
AlertPopupCustomLocation | Gets or sets where the alert appears when it is shown by an overload that takes no location. |
AlertPopupIsShownAgainWhenMousePointerIsOver | Gets or sets whether an alert that is going away comes back when the pointer moves onto it. |
AlertPopupIsShownWhenMouseIsOver | Gets or sets whether the alert stays on screen past its visible time while the pointer is over it. |
AlertPopupStyle | Gets or sets which built-in skin the alert wears: Outlook's or MSN Messenger's. |
AlertTextSelectionRectangleColor | Gets or sets the colour of the dotted rectangle drawn round the body text while the pointer is over it. |
AlertTitleText | Gets or sets the title drawn at the top of the alert. |
AllowUserToDragDropPopupWindow | Gets or sets whether the user can move the alert by dragging the strip along its top edge. |
CanClickAlertText | Gets or sets whether the body text reacts to the pointer and raises PopupMessageTextClicked when clicked. |
CanClickExitButton | Gets or sets whether the exit button responds to the pointer and to clicks. |
CanClickTitle | Gets or sets whether the title reacts to the pointer and raises PopupTitleTextClicked when clicked. |
ColorToUseForFillingContextMenuDropDownChevronRectangleWithSingleColor | Gets or sets the colour of the menu button's highlight when it is a single colour. |
ContextMenuDropDownChevronColor | Gets or sets the colour of the chevron drawn on the menu button. |
ContextMenuDropDownChevronRectangleBorderColor | Gets or sets the colour of the outline round the menu button while it is under the pointer or its menu is open. |
ControlDisappearingStyle | Gets or sets how the alert goes away: fading out, sliding back into its edge of the screen, or both. |
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. |
CustomAlertPopupWindowImageCanBeClicked | Gets or sets whether clicking an alert that shows CustomAlertPopupWindowImage raises PopupCustomImageClicked. |
CustomAlertTextArea | Gets or sets where the body text is drawn on the alert, in place of the style's own place for it. |
CustomExitIcon | Gets or sets an icon to draw as the exit button in place of the built-in one. |
CustomTitleIcon | Gets or sets the picture drawn as the alert's title icon, in place of the style's built-in one. |
CustomTitleIconAlignment | Gets or sets where on the alert the title icon is placed: one of nine positions. |
CustomTitleIconLocation | Gets or sets exactly where the title icon's top-left corner is placed on the alert. |
CustomTitleTextArea | Gets or sets where the title is drawn on the alert, in place of the style's own place for it. |
CustomUserWindowPaintSize | Gets or sets the size of the surface you draw on when EnableCustomUserPaint is set – the size the
alert window takes. |
DisplayExitButton | Gets or sets whether the alert has an exit button in its top right-hand corner. |
DrawUsingColorType | Gets or sets whether custom colours fill the alert's body with one colour or a gradient. |
DrawUsingCustomColors | Gets or sets whether the body of the skin is filled with colours of your own instead of the theme's. |
EnableCustomUserPaint | Gets or sets whether you draw the alert yourself, in a Control.Paint handler, instead of the built-in skin. |
EndColor | Gets or sets the colour the custom gradient in the alert's body ends in. |
EndColorToUseForFillingContextMenuDropDownChevronRectangleWithGradientColors | Gets or sets the colour the menu button's highlight gradient ends in. |
FillContextMenuDropDownChevronRectangleWithGradientColors | Gets or sets whether the menu button's highlight is a gradient rather than a single colour. |
GradientOrientationAngle | Gets or sets the direction of the gradient in the alert's body when it is drawn in custom colours. |
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. |
IsMouseCurrentlyDown | Gets whether a mouse button is held down on the alert. |
Opacity | Gets or sets how opaque the alert window is, from 0 (invisible) to 1 (solid). |
PlaySoundWhenPopupIsDisplayed | Gets or sets whether a sound is played each time the alert is shown. |
PopupAlertThemeColor | Gets or sets the colour scheme of the built-in skin: blue, olive green or silver. |
PopupScreenCorner | Gets or sets the corner of the screen's working area the alert appears in. |
ShouldPerformAdvancedCleanupUponHide | Gets or sets whether the alert releases its animation timer each time it is hidden, rather than keeping it for the next showing. |
ShowTextAreaRectangle | Gets or sets whether a dotted rectangle is drawn round the body text while the pointer is over it. |
SoundPlayBackFile | Gets or sets the full path of the sound file played when the alert is shown. |
SpecificColor | Gets or sets the single colour the alert's body is filled with when it is drawn in custom colours. |
StartColor | Gets or sets the colour the custom gradient in the alert's body starts from. |
StartColorToUseForFillingContextMenuDropDownChevronRectangleWithGradientColors | Gets or sets the colour the menu button's highlight gradient starts from. |
StretchTitleIconToCoverTheEntireControlArea | Gets or sets whether the title icon is stretched over the whole alert, as a background picture under the text. |
UseCustomAlertPopupWindowImage | Gets or sets whether the alert shows CustomAlertPopupWindowImage instead of its built-in skin. |
| Methods | |
CleanUpUponContextMenuItemClicked | Tells the alert that its menu has closed, and starts it going away. |
Dispose | Releases the timer that drives the animation and the skin bitmaps the alert made for itself. |
Hide | Takes the alert off the screen at once, without its going-away animation. |
KeepShowingUntilHiddenDeterministically | Keeps the alert on screen until Hide is called, instead of letting it go away after its visible time. |
OnClick | Raises Control.Click and clears the alert's open-menu state. |
OnMouseDown | Shows the exit button pressed, and starts a drag when the press is on the strip along the top. |
OnMouseEnter | Notes that the pointer is over the alert, which keeps it on screen while AlertPopupIsShownWhenMouseIsOver is set. |
OnMouseLeave | Notes that the pointer has left the alert, returning the title, text and buttons to their resting look. |
OnMouseMove | 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. |
OnMouseUp | Completes a click on the part of the alert under the pointer, raising the event for that part. |
OnPaint | Raises the Control.Paint event while EnableCustomUserPaint is set, and does nothing otherwise. |
OnPaintBackground | Draws the whole alert: skin, exit and menu buttons, title icon, title and body text. |
Show | Shows the alert with no title and no body text, with the standard timings. |
Show | Shows the alert with this title and body text, with the standard timings. |
Show | Shows the alert with this title and body text, taking the times you give for each phase. |
Show | Shows the alert with this title and body text, for the times you give, at a place of your choosing. |
| Events | |
AboutToPlaySound | Occurs each time the alert is shown, after AboutToPopup, before its sound would play. |
AboutToPopup | Occurs each time a Show method is called, before the alert appears. |
ContextMenuShown | Occurs when the user clicks the menu button, before the menu opens. |
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. |
PopupExitButtonClicked | Occurs when the user clicks the exit button, before the alert starts to go away. |
PopupMessageTextClicked | Occurs when the user clicks the body text, while CanClickAlertText is set. |
PopupTitleTextClicked | Occurs when the user clicks the title, while CanClickTitle is set. |
Constructors
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
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
Gets or sets the colour of the body text.
- Value
- The default is black.
- Designer category
- Color properties
See also
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
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
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
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
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
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 asAlertNormalTitleColor. - Designer category
- Color properties
Remarks
Used only while CanClickTitle is set.
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
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
Gets or sets whether an alert that is going away comes back when the pointer moves onto it.
- Value
trueto bring it back. The default isfalse.
Remarks
An alert closed with its exit button does not come back.
AlertPopupIsShownWhenMouseIsOver
Gets or sets whether the alert stays on screen past its visible time while the pointer is over it.
- Value
trueto keep it while the pointer rests anywhere on it. The default istrue.
Remarks
The alert starts to go away once the pointer leaves. That gives the user time to read and click.
See also
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
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
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
Gets or sets whether the user can move the alert by dragging the strip along its top edge.
- Value
trueto allow it. The default istrue.
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
Gets or sets whether the body text reacts to the pointer and raises PopupMessageTextClicked when clicked.
- Value
trueto make the text clickable. The default istrue.
Remarks
Under the pointer the text is drawn in AlertOnHoverBodyTextColor and
AlertOnHoverBodyTextFont, inside a dotted rectangle while ShowTextAreaRectangle is set.
CanClickExitButton
Gets or sets whether the exit button responds to the pointer and to clicks.
- Value
trueto let the user close the alert with it. The default istrue.
Remarks
Set it to false to leave the button on show but inert. To remove it, set
DisplayExitButton to false.
CanClickTitle
Gets or sets whether the title reacts to the pointer and raises PopupTitleTextClicked when clicked.
- Value
trueto make the title clickable. The default isfalse.
Remarks
While it is clickable the title is drawn in AlertOnHoverTitleColor and
AlertOnHoverTitleFont under the pointer, which shows a hand.
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
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 isnull. Shown only whileUseCustomAlertPopupWindowImageis 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
Gets or sets whether clicking an alert that shows CustomAlertPopupWindowImage raises PopupCustomImageClicked.
- Value
trueto raise the event. The default istrue.
Remarks
The pointer shows a hand over such an alert either way.
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
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
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 theAlertPopupStyle.
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
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
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 byCustomTitleIconAlignment.
Remarks
A location set here wins over the alignment until CustomTitleIconAlignment is set again or
this is set back to Point.Empty.
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
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
Gets or sets whether the alert has an exit button in its top right-hand corner.
- Value
trueto show it. The default istrue.- Designer category
- Popup Style properties
Remarks
Without it the alert goes away only by itself or by Hide.
See also
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
Gets or sets whether the body of the skin is filled with colours of your own instead of the theme's.
- Value
trueto use your colours. The default isfalse.- 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
Gets or sets whether you draw the alert yourself, in a Control.Paint handler, instead of the built-in skin.
- Value
trueto draw it yourself. The default isfalse.
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
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
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:
StartColorat the top,EndColorat the bottom. - Designer category
- Color properties
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
Gets whether a mouse button is held down on the alert.
- Value
truefrom a button press on the alert until its release.
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
Gets or sets whether a sound is played each time the alert is shown.
- Value
trueto playSoundPlayBackFile. The default isfalse.
Remarks
The sound plays in the background as the alert starts to appear. Handle AboutToPlaySound to
silence a particular showing.
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
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
Gets or sets whether the alert releases its animation timer each time it is hidden, rather than keeping it for the next showing.
- Value
trueto release it on every hide. The default isfalse.
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
Gets or sets whether a dotted rectangle is drawn round the body text while the pointer is over it.
- Value
trueto draw it. The default istrue.
Remarks
It marks the text as a link. Drawn in AlertTextSelectionRectangleColor, and only while
CanClickAlertText is set.
SoundPlayBackFile
Gets or sets the full path of the sound file played when the alert is shown.
- Value
- The path of a
.wavfile. 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
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
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.
StretchTitleIconToCoverTheEntireControlArea
Gets or sets whether the title icon is stretched over the whole alert, as a background picture under the text.
- Value
trueto stretch it. The default isfalse.
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
Gets or sets whether the alert shows CustomAlertPopupWindowImage instead of its built-in skin.
- Value
trueto show the picture. The default isfalse. Has no effect whileCustomAlertPopupWindowImageisnull.
See also
Methods
Dispose
Releases the timer that drives the animation and the skin bitmaps the alert made for itself.
Parameters
disposingtruewhen called fromDispose();falsewhen called from the finaliser.
Remarks
Images you supplied – CustomAlertPopupWindowImage, CustomTitleIcon,
CustomExitIcon – are not disposed; they remain yours.
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.
OnClick
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
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
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
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
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
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
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
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
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
Shows the alert with this title and body text, with the standard timings.
Parameters
theAlertTitle- The title, drawn on one line at the top.
nullor empty draws no title. theBodyText- The message, drawn centred in the body.
nullor 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
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.
nullor empty draws no title. theBodyText- The message, drawn centred in the body.
nullor 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
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.
nullor empty draws no title. theBodyText- The message, drawn centred in the body.
nullor 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
AlertPopupIsShownWhenMouseIsOveris 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
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
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;
};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
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
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
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.