Approved
Last Updated: 29 Mar 2016 12:11 by ADMIN
ADMIN
Hristo
Created on: 22 May 2015 07:50
Category: DesktopAlert
Type: Bug Report
1
FIX. RadDesktopAlert - wrong position of newly shown alerts if the screen resolution is being changed while the application is running
Workaround: keep track of the alerts and their location

public partial class Form1 : Form
{
    private Point location;
    private Rectangle initialRect;
    private bool displaySettingsChanged;
    private RadDesktopAlert dAlert;
    private HashSet<RadDesktopAlert> alerts;

    public Form1()
    {
        InitializeComponent();

        this.initialRect = Screen.PrimaryScreen.WorkingArea;
        this.radDesktopAlert1.Popup.LocationChanged += Popup_LocationChanged;
        Microsoft.Win32.SystemEvents.DisplaySettingsChanged += SystemEvents_DisplaySettingsChanged;
    }

    private void Popup_LocationChanged(object sender, EventArgs e)
    {
        DesktopAlertPopup popup = sender as DesktopAlertPopup;
        RadDesktopAlert alert = this.alerts.Where(a => a.Popup == popup).FirstOrDefault();
        if ((alert.Popup.Location.X != this.location.X || alert.Popup.Location.Y != this.location.X) && this.displaySettingsChanged && Control.MouseButtons != MouseButtons.Left)
        {
            alert.Popup.Location = this.location;
        }
    }

    private void SystemEvents_DisplaySettingsChanged(object sender, EventArgs e)
    {
        this.displaySettingsChanged = true;
        foreach (RadDesktopAlert alert in this.alerts)
        {
            this.AdjustPosition(alert);
        }
    }

    private void AdjustPosition(RadDesktopAlert alert)
    {
        Rectangle newRect = Screen.PrimaryScreen.WorkingArea;
        Point newLocation = DesktopAlertManager.Instance.GetAlertPopupLocation(alert);
        this.location = new Point(newLocation.X - (initialRect.Width - newRect.Width), newLocation.Y - (initialRect.Height - newRect.Height));
        alert.Popup.Location = this.location;
    }

    private void radButton1_Click(object sender, EventArgs e)
    {
        this.dAlert = new RadDesktopAlert();
        this.dAlert.PopupAnimationFrames = 1;
        this.dAlert.CanMove = false;
        this.dAlert.Show();

        if (this.alerts == null)
        {
            this.alerts = new HashSet<RadDesktopAlert>();
        }

        this.alerts.Add(this.dAlert);
        this.dAlert.Popup.LocationChanged += Popup_LocationChanged;
        if (this.displaySettingsChanged)
        {
            this.AdjustPosition(dAlert);
        }
    }
}
0 comments