New to Telerik UI for WinForms? Start a free 30-day trial
How to position the RadDesktopAlert control in the center of a Form
Updated over 6 months ago
Environment
| Product Version | Product | Author |
|---|---|---|
| 2022.3.913 | RadDesktopAlert for WinForms | Dinko Krastev |
Description
This tutorial demonstrates how to position the RadDesktopAlert control in the center of a Form.
Solution
To center the RadDesktopAlert control in your Form, you can subscribe to the LocationChanged event. Inside the event handler, you can calculate the location so that the popup will be positioned in the form center. The following code snippet demonstrates how this can be achieved.
C#
private void radButton1_Click(object sender, EventArgs e)
{
this.radDesktopAlert1.Popup.LocationChanged += Popup_LocationChanged;
this.radDesktopAlert1.CaptionText = "New E-mail Notification";
this.radDesktopAlert1.ContentText = "Hello Jack, I am writing to inform you " +
"that the planning meeting scheduled for Wednesday has been postponed and" +
"it will eventually be rescheduled, possibly for the next Tuesday";
this.radDesktopAlert1.Show();
}
int x = 0;
int y = 0;
private void Popup_LocationChanged(object sender, EventArgs e)
{
DesktopAlertPopup popup = sender as DesktopAlertPopup;
if (popup != null)
{
x = this.Location.X + this.Width/2 - popup.Size.Width/2;
y = this.Location.Y + this.Height/2 - popup.Size.Height/2;
popup.Location = new Point(x, y);
}
}