/// <summary> /// Create new Notification /// </summary> /// <param name="title">title text</param> /// <param name="body">main body, as text or HTML</param> /// <param name="buttons">optional list of buttons</param> /// <param name="animation">optional animation overrides</param> public Notification(string title, string body, int hideInMs = 0, List<NotificationButton> buttons = null, NotificationAnimation animation = null) : base() { InitializeComponent(); if (animation == null) { animation = new NotificationAnimation(); } lifeTimer.Interval = (hideInMs > 0 ? hideInMs : int.MaxValue); // set the title labelTitle.Text = title; // show or hide the buttons _buttons = buttons; if (_buttons == null || _buttons.Count == 0) { buttonPanel.Visible = false; } else { buttonPanel.Visible = true; this.Height += buttonPanel.Height; this.labelBody.Height -= buttonPanel.Height; this.htmlBody.Height -= buttonPanel.Height; if (_buttons.Count >= 1) { button1.Text = _buttons[0].Text; button1.Tag = _buttons[0]; } if (_buttons.Count >= 2) { button2.Text = _buttons[1].Text; button2.Tag = _buttons[1]; button2.Visible = true; } if (_buttons.Count >= 3) { button3.Text = _buttons[2].Text; button3.Tag = _buttons[2]; button3.Visible = true; } } // set the body text or html if (body.IndexOf("<") == -1) { labelBody.Text = body; labelBody.Visible = true; } else { // inject browser TheArtOfDev.HtmlRenderer.WinForms.HtmlPanel browser = new TheArtOfDev.HtmlRenderer.WinForms.HtmlPanel(); browser.Dock = DockStyle.Fill; browser.Location = new Point(0, 0); browser.Size = new Size(htmlBody.Width, htmlBody.Height); htmlBody.Controls.Add(browser); browser.Text = "<!doctype html><html><head><meta charset=\"UTF-8\"><style>html,body{width:100%;height:100%;margin:0;padding:0;}body{margin:0 5px;font-size:14px;border:1px;}h1{font-size:16px;font-weight:normal;margin:0;padding:0 0 4px 0;}</style></head><body>" + body + "</body></html>"; browser.AutoScroll = false; browser.IsSelectionEnabled = false; browser.Click += Notification_Click; htmlBody.Visible = true; } if (OnNotificationClicked != null) { this.labelBody.Cursor = Cursors.Hand; this.htmlBody.Cursor = Cursors.Hand; } _animator = new FormAnimator(this, animation.Method, animation.Direction, 500); //Region = Region.FromHrgn(CreateRoundRectRgn(0, 0, Width - 5, Height - 5, 5, 5)); }
/// <summary> /// Create new Notification /// </summary> /// <param name="title">title text</param> /// <param name="body">main body, as text or HTML</param> /// <param name="buttons">optional list of buttons</param> /// <param name="animation">optional animation overrides</param> public Notification(string title, string body, int hideInMs = 0, List <NotificationButton> buttons = null, NotificationAnimation animation = null) : base() { InitializeComponent(); if (animation == null) { animation = new NotificationAnimation(); } lifeTimer.Interval = (hideInMs > 0 ? hideInMs : int.MaxValue); // set the title labelTitle.Text = title; // show or hide the buttons _buttons = buttons; if (_buttons == null || _buttons.Count == 0) { buttonPanel.Visible = false; } else { buttonPanel.Visible = true; this.Height += buttonPanel.Height; this.labelBody.Height -= buttonPanel.Height; this.htmlBody.Height -= buttonPanel.Height; if (_buttons.Count >= 1) { button1.Text = _buttons[0].Text; button1.Tag = _buttons[0]; } if (_buttons.Count >= 2) { button2.Text = _buttons[1].Text; button2.Tag = _buttons[1]; button2.Visible = true; } if (_buttons.Count >= 3) { button3.Text = _buttons[2].Text; button3.Tag = _buttons[2]; button3.Visible = true; } } // set the body text or html if (body.IndexOf("<") == -1) { labelBody.Text = body; labelBody.Visible = true; } else { // inject browser TheArtOfDev.HtmlRenderer.WinForms.HtmlPanel browser = new TheArtOfDev.HtmlRenderer.WinForms.HtmlPanel(); browser.Dock = DockStyle.Fill; browser.Location = new Point(0, 0); browser.Size = new Size(htmlBody.Width, htmlBody.Height); htmlBody.Controls.Add(browser); browser.Text = "<!doctype html><html><head><meta charset=\"UTF-8\"><style>html,body{width:100%;height:100%;margin:0;padding:0;}body{margin:0 5px;font-size:14px;border:1px;}h1{font-size:16px;font-weight:normal;margin:0;padding:0 0 4px 0;}</style></head><body>" + body + "</body></html>"; browser.AutoScroll = false; browser.IsSelectionEnabled = false; browser.Click += Notification_Click; htmlBody.Visible = true; } if (OnNotificationClicked != null) { this.labelBody.Cursor = Cursors.Hand; this.htmlBody.Cursor = Cursors.Hand; } _animator = new FormAnimator(this, animation.Method, animation.Direction, 500); //Region = Region.FromHrgn(CreateRoundRectRgn(0, 0, Width - 5, Height - 5, 5, 5)); }
private void Notify(string Message) { Notification.Visibility = Visibility.Visible; NotificationText.Text = Message; NotificationAnimation.Begin(); }