Back to Devexpress

How to: Make an Alert Window Opaque

windowsforms-5404-controls-and-libraries-messages-notifications-and-dialogs-alert-windows-how-to-make-an-alert-window-opaque.md

latest3.5 KB
Original Source

How to: Make an Alert Window Opaque

  • Nov 13, 2018
  • 2 minutes to read

This example displays an alert window and demonstrates how to respond to clicking the alert window’s content. The shown alert window is made opaque in the BeforeFormShow event handler.

csharp
using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ShowAlertWindow {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }

        private void simpleButton1_Click(object sender, EventArgs e) {
            Message msg = new Message();
            alertControl1.Show(this, msg.Caption, msg.Text, "", msg.Image, msg);
        }

        private void alertControl1_BeforeFormShow(object sender, DevExpress.XtraBars.Alerter.AlertFormEventArgs e) {
            //Make the Alert Window opaque
            e.AlertForm.OpacityLevel = 1;
        }

        private void alertControl1_AlertClick(object sender, DevExpress.XtraBars.Alerter.AlertClickEventArgs e) {
            //Process Alert Window click
            Message msg = e.Info.Tag as Message;
            XtraMessageBox.Show(msg.Text, msg.Caption);
        }
    }

    public class Message {
        public Message() {
            this.Caption = "LILA-Supermercado";
            this.Text = "Carrera 52 con Ave. Bolívar #65-98 Llano Largo";
            this.Image = global::ShowAlertWindow.Properties.Resources.opportunities_32x32;
        }
        public string Caption { get; set; }
        public string Text { get; set; }
        public Image Image { get; set; }
    }
}
vb
Imports DevExpress.XtraEditors
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Imports System.Windows.Forms

Namespace ShowAlertWindow
    Partial Public Class Form1
        Inherits Form

        Public Sub New()
            InitializeComponent()
        End Sub

        Private Sub simpleButton1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles simpleButton1.Click
            Dim msg As New Message()
            alertControl1.Show(Me, msg.Caption, msg.Text, "", msg.Image, msg)
        End Sub

        Private Sub alertControl1_BeforeFormShow(ByVal sender As Object, ByVal e As DevExpress.XtraBars.Alerter.AlertFormEventArgs) Handles alertControl1.BeforeFormShow
            'Make the Alert Window opaque
            e.AlertForm.OpacityLevel = 1
        End Sub

        Private Sub alertControl1_AlertClick(ByVal sender As Object, ByVal e As DevExpress.XtraBars.Alerter.AlertClickEventArgs) Handles alertControl1.AlertClick
            'Process Alert Window click
            Dim msg As Message = TryCast(e.Info.Tag, Message)
            XtraMessageBox.Show(msg.Text, msg.Caption)
        End Sub
    End Class

    Public Class Message
        Public Sub New()
            Me.Caption = "LILA-Supermercado"
            Me.Text = "Carrera 52 con Ave. Bolívar #65-98 Llano Largo"
            Me.Image = My.Resources.opportunities_32x32
        End Sub
        Public Property Caption() As String
        Public Property Text() As String
        Public Property Image() As Image
    End Class
End Namespace