Skip to main content
All docs
V25.1
  • OverlayWindowOptions.CustomPainter Property

    Gets or sets an object used to paint a form.

    Namespace: DevExpress.XtraSplashScreen

    Assembly: DevExpress.XtraEditors.v25.1.dll

    NuGet Package: DevExpress.Win.Navigation

    Declaration

    public IOverlayWindowPainter CustomPainter { get; set; }

    Property Value

    Type Description
    DevExpress.XtraSplashScreen.IOverlayWindowPainter

    An object that implements a custom paint logic.

    Property Paths

    You can access this nested property as listed below:

    Library Object Type Path to CustomPainter
    WinForms Controls OverlayWindowOptions
    .Default .CustomPainter
    XAF: Cross-Platform .NET App UI & Web API DefaultOverlayFormOptions
    .Options .CustomPainter

    Example

    To draw an Overlay Form manually, do the following:

    1. Create a class that inherits from OverlayWindowPainterBase.
    2. Override the Draw method to define custom rendering..
    3. Instantiate the custom painter (CustomOverlayPainter) and pass it to the ShowOverlayForm method.

    Display Custom Overlay Form - WinForms, DevExpress

    using DevExpress.Utils.Drawing;
    using DevExpress.XtraEditors;
    using DevExpress.XtraSplashScreen;
    using System;
    using System.Drawing;
    using System.Threading.Tasks;
    
    namespace DXOverlayFormDemo {
        public partial class Form1 : XtraForm {
            public Form1() {
                InitializeComponent();
                this.Load += MainForm_Load;
            }
    
            async void MainForm_Load(object sender, EventArgs e) {
                IOverlaySplashScreenHandle handle = null;
                try {
                    handle = SplashScreenManager.ShowOverlayForm(this, customPainter: new CustomOverlayPainter());
                    // Emulate a long-running operation (5 seconds).
                    await Task.Delay(5000);
                }
                finally {
                    if (handle != null)
                        SplashScreenManager.CloseOverlayForm(handle);
                }
            }
    
        }
    
        class CustomOverlayPainter : OverlayWindowPainterBase {
            static readonly Font drawFont;
            static CustomOverlayPainter() {
                drawFont = new Font("Tahoma", 14);
            }
            protected override void Draw(OverlayWindowCustomDrawContext context) {
                // Set Handled to true to disable the default drawing. 
                context.Handled = true;
    
                // Access the drawing surface.
                GraphicsCache cache = context.DrawArgs.Cache;
    
                // Improve text rendering quality.
                cache.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
    
                // Get the bounds of the overlapped control. 
                Rectangle bounds = context.DrawArgs.Bounds;
    
                // Draw the default background. 
                context.DrawBackground();
    
                // Specify the message to display instead of the Overlay Form.
                String drawString = "Loading...";
    
                // Use the system black brush for drawing text.
                Brush drawBrush = Brushes.Black;
    
                // Calculate the size of the text string.
                SizeF textSize = cache.CalcTextSize(drawString, drawFont);
    
                // Determine the upper-left corner for centered text.
                PointF drawPoint = new PointF(
                    bounds.Left + bounds.Width / 2 - textSize.Width / 2,
                    bounds.Top + bounds.Height / 2 - textSize.Height / 2
                    );
    
                // Draw the text on the Overlay Form.
                cache.DrawString(drawString, drawFont, drawBrush, drawPoint);
            }
        }
    }
    
    See Also