public void ShowNotification(SimpleNotification notification) { lock (notificationLock) { List <Control> controls = new List <Control>(); int x = 0, y = notifications.Count * 65; // background label Label background = new Label(); background.Size = notification.Size; background.BackColor = notification.BackColor; background.Location = new Point(x, UpsideDown ? this.Size.Height - y - background.Height : y); background.Click += Background_Click; this.Controls.Add(background); foreach (Control c in notification.Controls) { controls.Add(c); } foreach (Control c in controls) { c.Location = new Point(x + c.Location.X, background.Location.Y + c.Location.Y); this.Controls.Add(c); if (c.BackgroundImage == null) { c.BackColor = notification.BackColor; } if (c.Name.Length == 0) { c.Click += Background_Click; } c.BringToFront(); } notifications.Add(controls); controls.Add(background); System.Timers.Timer closeTimer = new System.Timers.Timer(Math.Max(SettingsManager.getSettingInt("PopupDuration"), 1) * 1000); closeTimer.Elapsed += CloseTimer_Elapsed; closeTimer.Enabled = true; closeTimer.AutoReset = false; } }
public void ShowNotification(SimpleNotification notification) { lock (notificationLock) { List <Control> controls = new List <Control>(); int x = 0, y = notifications.Count * 65; // background label Label background = new Label(); background.Size = notification.Size; background.BackColor = notification.BackColor; background.Location = new Point(x, UpsideDown ? this.Size.Height - y - background.Height : y); background.Click += Background_Click; this.Controls.Add(background); foreach (Control c in notification.Controls) { controls.Add(c); } foreach (Control c in controls) { c.Location = new Point(x + c.Location.X, background.Location.Y + c.Location.Y); this.Controls.Add(c); if (c.BackgroundImage == null) { c.BackColor = notification.BackColor; } if (c.Name.Length == 0) { c.Click += Background_Click; } c.BringToFront(); } notifications.Add(controls); controls.Add(background); System.Threading.Tasks.Task.Delay(Math.Max(SettingsManager.getSettingInt("PopupDuration"), 1) * 1000).ContinueWith(t => ClosePopup()); } }
public static void simpleNotificationClosed(object sender, FormClosedEventArgs e) { if (clearSimpleNotifications) { return; } lock (popupLock) { SimpleNotification notification = sender as SimpleNotification; if (notification == null) { return; } bool moveDown = false; int positionModification = 0; int anchor = SettingsManager.getSettingInt("SimpleNotificationAnchor"); int sign = 1; switch (anchor) { case 0: case 1: sign = -1; break; } foreach (SimpleNotification f in notificationStack) { if (f == notification) { positionModification = sign * (f.Height + notificationSpacing); moveDown = true; } else if (moveDown) { f.targetPositionY += positionModification; } } notificationStack.Remove(notification); } }
public void ShowNotification(SimpleNotification notification) { lock (notificationLock) { List<Control> controls = new List<Control>(); int x = 0, y = notifications.Count * 65; // background label Label background = new Label(); background.Size = notification.Size; background.BackColor = notification.BackColor; background.Location = new Point(x, UpsideDown ? this.Size.Height - y - background.Height : y); background.Click += Background_Click; this.Controls.Add(background); foreach (Control c in notification.Controls) { controls.Add(c); } foreach (Control c in controls) { c.Location = new Point(x + c.Location.X, background.Location.Y + c.Location.Y); this.Controls.Add(c); if (c.BackgroundImage == null) { c.BackColor = notification.BackColor; } if (c.Name.Length == 0) { c.Click += Background_Click; } c.BringToFront(); } notifications.Add(controls); controls.Add(background); System.Threading.Tasks.Task.Delay(Math.Max(SettingsManager.getSettingInt("PopupDuration"), 1) * 1000).ContinueWith(t => ClosePopup()); } }
public static void ShowSimpleNotification(SimpleNotification f) { lock (popupLock) { if (popupContainer != null) { popupContainer.ShowNotification(f); return; } int position_x = 0, position_y = 0; Screen screen = ProcessManager.GetScreen(); int simpleX = SettingsManager.getSettingInt("SimpleNotificationXOffset"); int simpleY = SettingsManager.getSettingInt("SimpleNotificationYOffset"); int xOffset = simpleX < 0 ? 30 : simpleX; int yOffset = simpleY < 0 ? 30 : simpleY; int anchor = SettingsManager.getSettingInt("SimpleNotificationAnchor"); int sign = 1; int basePosition = screen.WorkingArea.Bottom - yOffset; int startX = 0; switch (anchor) { case 0: case 1: // Top sign = -1; basePosition = screen.WorkingArea.Top + yOffset; break; case 2: default: // Bottom break; } switch (anchor) { case 0: case 2: // Left position_x = screen.WorkingArea.Left + xOffset; startX = position_x - (f.Width + notificationSpacing); break; case 1: default: // Right position_x = screen.WorkingArea.Right - f.Width - notificationSpacing - xOffset; startX = position_x + f.Width + notificationSpacing; break; } foreach (SimpleNotification notification in notificationStack) { basePosition -= sign * (notification.Height + notificationSpacing); } position_y = basePosition - sign * f.Height; f.StartPosition = FormStartPosition.Manual; if (!SettingsManager.getSettingBool("EnableSimpleNotificationAnimation")) { startX = position_x; } f.SetDesktopLocation(startX, position_y); f.targetPositionX = position_x; f.targetPositionY = position_y; f.FormClosed += simpleNotificationClosed; notificationStack.Add(f); f.TopMost = true; f.Show(); } }
private void ShowSimpleNotification(SimpleNotification f) { int position_x = 0, position_y = 0; Screen screen; Process tibia_process = GetTibiaProcess(); if (tibia_process == null) { screen = Screen.FromControl(this); } else { screen = Screen.FromHandle(tibia_process.MainWindowHandle); } int simpleX = SettingsManager.getSettingInt("SimpleNotificationXOffset"); int simpleY = SettingsManager.getSettingInt("SimpleNotificationYOffset"); int xOffset = simpleX < 0 ? 30 : simpleX; int yOffset = simpleY < 0 ? 30 : simpleY; int anchor = SettingsManager.getSettingInt("SimpleNotificationAnchor"); int sign = 1; int basePosition = screen.WorkingArea.Bottom - yOffset; int startX = 0; switch (anchor) { case 0: case 1: // Top sign = -1; basePosition = screen.WorkingArea.Top + yOffset; break; case 2: default: // Bottom break; } switch (anchor) { case 0: case 2: // Left position_x = screen.WorkingArea.Left + xOffset; startX = position_x - (f.Width + notificationSpacing); break; case 1: default: // Right position_x = screen.WorkingArea.Right - f.Width - notificationSpacing - xOffset; startX = position_x + f.Width + notificationSpacing; break; } foreach (SimpleNotification notification in notificationStack) { basePosition -= sign * (notification.Height + notificationSpacing); } position_y = basePosition - sign * f.Height; f.StartPosition = FormStartPosition.Manual; if (!SettingsManager.getSettingBool("EnableSimpleNotificationAnimation")) { startX = position_x; } f.SetDesktopLocation(startX, position_y); f.targetPositionX = position_x; f.targetPositionY = position_y; f.FormClosed += simpleNotificationClosed; notificationStack.Add(f); f.TopMost = true; f.Show(); }