using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Text; using System.Windows.Forms; namespace DevComponents.DotNetBar.Controls { /// /// Displays the desktop alerts with optional image or symbol. Text on alerts supports text-markup. /// public static class DesktopAlert { /// /// Shows desktop alert. /// /// Text to show on the alert. Text supports text-markup. public static void Show(string text) { Show(text, _AlertColor, _AlertPosition, null); } /// /// Shows desktop alert. /// /// Text to show on the alert. Text supports text-markup. /// Specifies reference control which is used to find target screen alert is displayed on. public static void Show(string text, Control referenceControl) { Show(text, _AlertColor, _AlertPosition, null, referenceControl); } /// /// Shows desktop alert. /// /// Text to show on the alert. Text supports text-markup. /// Text-markup link click event handler. public static void Show(string text, MarkupLinkClickEventHandler markupLinkClickHandler) { Show(text, _AlertColor, _AlertPosition, markupLinkClickHandler); } /// /// Shows desktop alert. /// /// Text to show on the alert. Text supports text-markup. /// Specifies alert color. public static void Show(string text, eDesktopAlertColor alertColor) { Show(text, alertColor, _AlertPosition, null); } /// /// Shows desktop alert. /// /// Text to show on the alert. Text supports text-markup. /// Specifies alert color. /// Specifies reference control which is used to find target screen alert is displayed on. public static void Show(string text, eDesktopAlertColor alertColor, Control referenceControl) { Show(text, alertColor, _AlertPosition, null, referenceControl); } /// /// Shows desktop alert at specific screen position. /// /// Text to show on the alert. Text supports text-markup. /// Alert position on the screen. public static void Show(string text, eAlertPosition position) { Show(text, _AlertColor, position, null); } /// /// Shows desktop alert at specific screen position. /// /// Text to show on the alert. Text supports text-markup. /// Alert position on the screen. /// Specifies reference control which is used to find target screen alert is displayed on. public static void Show(string text, eAlertPosition position, Control referenceControl) { Show(text, _AlertColor, position, null, referenceControl); } /// /// Shows desktop alert at specific screen position. /// /// Text to show on the alert. Text supports text-markup. /// Image to display on alert. public static void Show(string text, Image image) { Show(text, image, _AlertColor, _AlertPosition, _AutoCloseTimeOut, 0, null); } /// /// Shows desktop alert. /// /// Text to show on the alert. Text supports text-markup. /// Alert color. /// Alert position on the screen. public static void Show(string text, eDesktopAlertColor alertColor, eAlertPosition position) { Show(text, alertColor, position, null); } /// /// Shows desktop alert. /// /// Text to show on the alert. Text supports text-markup. /// Alert color /// Alert position on the screen /// Text-markup link click event handler. /// Specifies reference control which is used to find target screen alert is displayed on. public static void Show(string text, eDesktopAlertColor alertColor, eAlertPosition position, MarkupLinkClickEventHandler markupLinkClickHandler, Control referenceControl) { DesktopAlertWindow alert = new DesktopAlertWindow(); alert.Text = text; alert.MaximumSize = Dpi.Size(_MaximumAlertSize); alert.AlertPosition = position; alert.AutoCloseTimeOut = _AutoCloseTimeOut; alert.TextMarkupEnabled = _TextMarkupEnabled; if (markupLinkClickHandler != null) alert.MarkupLinkClick += markupLinkClickHandler; alert.AlertAnimationDuration = _AlertAnimationDuration; alert.PlaySound = _PlaySound; alert.ReferenceControl = referenceControl; SetColors(alert, alertColor); alert.Show(); } /// /// Shows desktop alert. /// /// Text to show on the alert. Text supports text-markup. /// Alert color /// Alert position on the screen /// Text-markup link click event handler. public static void Show(string text, eDesktopAlertColor alertColor, eAlertPosition position, MarkupLinkClickEventHandler markupLinkClickHandler) { Show(text, alertColor, position, markupLinkClickHandler, null); } /// /// Shows desktop alert. /// /// Text to show on the alert. Text supports text-markup. /// Alert ID used to recognize alert if clicked and specified Action is called /// Action method to call if alert is clicked. public static void Show(string text, long alertId, Action alertClickAction) { Show(text, null, _AlertColor, _AlertPosition, _AutoCloseTimeOut, alertId, alertClickAction); } /// /// Shows desktop alert. /// /// Text to show on the alert. Text supports text-markup. /// Alert color /// Alert ID used to recognize alert if clicked and specified Action is called /// Action method to call if alert is clicked. public static void Show(string text, eDesktopAlertColor alertColor, long alertId, Action alertClickAction) { Show(text, null, alertColor, _AlertPosition, _AutoCloseTimeOut, alertId, alertClickAction); } /// /// Shows desktop alert. /// /// Text to show on the alert. Text supports text-markup. /// Symbol to show on the alert, see http://www.devcomponents.com/kb2/?p=1347 /// Symbol set to use /// Symbol color or Color.Empty to use default text color /// Alert color /// Alert position on the screen /// Duration of alert in the seconds. /// Alert ID used to recognize alert if clicked and specified Action is called /// Action method to call if alert is clicked. public static void Show(string text, string symbol, eSymbolSet symbolSet, Color symbolColor, eDesktopAlertColor alertColor, eAlertPosition position, int alertDurationSeconds, long alertId, Action alertClickAction) { Show(text, symbol, symbolSet, symbolColor, alertColor,position, alertDurationSeconds, alertId, alertClickAction, null); } /// /// Shows desktop alert. /// /// Text to show on the alert. Text supports text-markup. /// Symbol to show on the alert, see http://www.devcomponents.com/kb2/?p=1347 /// Symbol set to use /// Symbol color or Color.Empty to use default text color /// Alert position on the screen /// Alert color /// Duration of alert in the seconds. /// Alert ID used to recognize alert if clicked and specified Action is called /// Action method to call if alert is clicked. /// Text-markup link click event handler. public static void Show(string text, string symbol, eSymbolSet symbolSet, Color symbolColor, eDesktopAlertColor alertColor, eAlertPosition position, int alertDurationSeconds, long alertId, Action alertClickAction, MarkupLinkClickEventHandler markupLinkClickHandler) { Show(text, symbol, symbolSet, symbolColor, alertColor, position, alertDurationSeconds, alertId, alertClickAction, markupLinkClickHandler, null); } /// /// Shows desktop alert. /// /// Text to show on the alert. Text supports text-markup. /// Symbol to show on the alert, see http://www.devcomponents.com/kb2/?p=1347 /// Symbol set to use /// Symbol color or Color.Empty to use default text color /// Alert position on the screen /// Alert color /// Duration of alert in the seconds. /// Alert ID used to recognize alert if clicked and specified Action is called /// Action method to call if alert is clicked. /// Text-markup link click event handler. /// Specifies reference control which is used to find target screen alert is displayed on. public static void Show(string text, string symbol, eSymbolSet symbolSet, Color symbolColor, eDesktopAlertColor alertColor, eAlertPosition position, int alertDurationSeconds, long alertId, Action alertClickAction, MarkupLinkClickEventHandler markupLinkClickHandler, Control referenceControl) { DesktopAlertWindow alert = new DesktopAlertWindow(); alert.Text = text; alert.MaximumSize = Dpi.Size(_MaximumAlertSize); alert.AlertPosition = position; alert.Symbol = symbol; alert.SymbolSet = symbolSet; alert.SymbolColor = symbolColor; alert.AlertId = alertId; alert.ClickAction = alertClickAction; alert.AutoCloseTimeOut = alertDurationSeconds; alert.TextMarkupEnabled = _TextMarkupEnabled; if (markupLinkClickHandler != null) alert.MarkupLinkClick += markupLinkClickHandler; alert.AlertAnimationDuration = _AlertAnimationDuration; alert.PlaySound = _PlaySound; alert.ReferenceControl = referenceControl; SetColors(alert, alertColor); alert.Show(); } /// /// Shows desktop alert. /// /// Text to show on the alert. Text supports text-markup. /// Image to display on the alert /// Alert screen position /// Alert color /// Duration of alert in seconds /// Alert ID used to recognize alert if clicked and specified Action is called /// Action method to call if alert is clicked. public static void Show(string text, Image image, eDesktopAlertColor alertColor, eAlertPosition position, int alertDurationSeconds, long alertId, Action alertClickAction) { Show(text, image, alertColor, position, alertDurationSeconds, alertId, alertClickAction, null); } /// /// Shows desktop alert. /// /// Text to show on the alert. Text supports text-markup. /// Image to display on the alert /// Alert screen position /// Alert color /// Duration of alert in seconds /// Alert ID used to recognize alert if clicked and specified Action is called /// Action method to call if alert is clicked. /// Text-markup link click event handler. public static void Show(string text, Image image, eDesktopAlertColor alertColor, eAlertPosition position, int alertDurationSeconds, long alertId, Action alertClickAction, MarkupLinkClickEventHandler markupLinkClickHandler) { Show(text, image, alertColor, position, alertDurationSeconds, alertId, alertClickAction, markupLinkClickHandler, null); } /// /// Shows desktop alert. /// /// Text to show on the alert. Text supports text-markup. /// Image to display on the alert /// Alert screen position /// Alert color /// Duration of alert in seconds /// Alert ID used to recognize alert if clicked and specified Action is called /// Action method to call if alert is clicked. /// Text-markup link click event handler. /// Specifies reference control which is used to find target screen alert is displayed on. public static void Show(string text, Image image, eDesktopAlertColor alertColor, eAlertPosition position, int alertDurationSeconds, long alertId, Action alertClickAction, MarkupLinkClickEventHandler markupLinkClickHandler, Control referenceControl) { DesktopAlertWindow alert = new DesktopAlertWindow(); alert.Text = text; alert.MaximumSize = Dpi.Size(_MaximumAlertSize); alert.AlertPosition = position; alert.Image = image; alert.AlertId = alertId; alert.ClickAction = alertClickAction; alert.AutoCloseTimeOut = alertDurationSeconds; alert.TextMarkupEnabled = _TextMarkupEnabled; if (markupLinkClickHandler != null) alert.MarkupLinkClick += markupLinkClickHandler; alert.AlertAnimationDuration = _AlertAnimationDuration; alert.PlaySound = _PlaySound; alert.ReferenceControl = referenceControl; SetColors(alert, alertColor); alert.Show(); } private static void SetColors(DesktopAlertWindow w, eDesktopAlertColor c) { if (c == eDesktopAlertColor.Default) { w.BackColor = ColorScheme.GetColor(0x0078D7); w.ForeColor = Color.White; } else if (c == eDesktopAlertColor.Black) { w.BackColor = Color.Black; w.ForeColor = Color.White; } else if (c == eDesktopAlertColor.Blue) { w.BackColor = ColorScheme.GetColor(0x5B9BD5); w.ForeColor = Color.White; } else if (c == eDesktopAlertColor.BlueGray) { w.BackColor = ColorScheme.GetColor(0x44546A); w.ForeColor = Color.White; } else if (c == eDesktopAlertColor.DarkBlue) { w.BackColor = ColorScheme.GetColor(0x4472C4); w.ForeColor = Color.White; } else if (c == eDesktopAlertColor.DarkRed) { w.BackColor = ColorScheme.GetColor(0xC00000); w.ForeColor = Color.White; } else if (c == eDesktopAlertColor.Gold) { w.BackColor = ColorScheme.GetColor(0xFFC000); w.ForeColor = Color.Black; } else if (c == eDesktopAlertColor.Gray) { w.BackColor = ColorScheme.GetColor(0xE7E6E6); w.ForeColor = Color.Black; } else if (c == eDesktopAlertColor.Green) { w.BackColor = ColorScheme.GetColor(0x375623); w.ForeColor = Color.White; } else if (c == eDesktopAlertColor.Orange) { w.BackColor = ColorScheme.GetColor(0xCA5010); w.ForeColor = Color.White; } else if (c == eDesktopAlertColor.Red) { w.BackColor = ColorScheme.GetColor(0xE81123); w.ForeColor = Color.White; } } private static Size _MaximumAlertSize = new Size(400, 128); /// /// Indicates maximum alert size. /// public static Size MaximumAlertSize { get { return _MaximumAlertSize; } set { _MaximumAlertSize = value; } } private static eAlertPosition _AlertPosition = eAlertPosition.BottomRight; /// /// Specifies default alert screen position. /// public static eAlertPosition AlertPosition { get { return _AlertPosition; } set { _AlertPosition = value; } } private static eDesktopAlertColor _AlertColor = eDesktopAlertColor.Default; /// /// Specifies default alert color. /// public static eDesktopAlertColor AlertColor { get { return _AlertColor; } set { _AlertColor = value; } } private static int _AlertAnimationDuration = 200; /// /// Gets or sets the total time in milliseconds alert animation takes. /// Default value is 200. /// public static int AlertAnimationDuration { get { return _AlertAnimationDuration; } set { _AlertAnimationDuration = value; } } private static int _AutoCloseTimeOut = 6; /// /// Gets or sets time period in seconds after alert closes automatically. /// public static int AutoCloseTimeOut { get { return _AutoCloseTimeOut; } set { _AutoCloseTimeOut = value; } } private static bool _TextMarkupEnabled = true; /// /// Gets or sets whether text-markup can be used in alert text, default value is true. /// public static bool TextMarkupEnabled { get { return _TextMarkupEnabled; } set { _TextMarkupEnabled = value; } } private static bool _PlaySound = true; /// /// Indicates whether alert plays exclamation sound when shown. /// public static bool PlaySound { get { return _PlaySound; } set { _PlaySound = value; } } /// /// Occurs before alert is displayed and allows access to the alert Window through sender. /// [Description("Occurs before alert is displayed and allows access to the alert Window through sender.")] public static event EventHandler BeforeAlertDisplayed; /// /// Raises BeforeAlertDisplayed event. /// /// Provides event arguments. internal static void OnBeforeAlertDisplayed(DesktopAlertWindow w, EventArgs e) { EventHandler h = BeforeAlertDisplayed; if (h != null) h(w, e); } /// /// Occurs after alert as been closed. /// [Description("Occurs after alert has been closed.")] public static event AlertClosedEventHandler AlertClosed; /// /// Raises RemovingToken event. /// /// Provides event arguments. internal static void OnAlertClosed(object sender, AlertClosedEventArgs e) { AlertClosedEventHandler handler = AlertClosed; if (handler != null) handler(sender, e); } } /// /// Defines delegate for AlertClosed event. /// /// Sender. /// Event arguments public delegate void AlertClosedEventHandler(object sender, AlertClosedEventArgs args); /// /// Defines event arguments for AlertClosed event. /// public class AlertClosedEventArgs : EventArgs { /// /// Specifies alert closure source. /// public readonly eAlertClosureSource ClosureSource; public AlertClosedEventArgs(eAlertClosureSource source) { ClosureSource = source; } } /// /// Defines predefined desktop alert colors. /// public enum eDesktopAlertColor { Default, DarkRed, Black, Gray, BlueGray, Blue, Orange, Gold, DarkBlue, Green, Red } }