Back to Devexpress

OverlayWindowOptions.CustomPainter Property

windowsforms-devexpress-dot-xtrasplashscreen-dot-overlaywindowoptions-3c4febec.md

latest7.2 KB
Original Source

OverlayWindowOptions.CustomPainter Property

Gets or sets an object used to paint a form.

Namespace : DevExpress.XtraSplashScreen

Assembly : DevExpress.XtraEditors.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
public IOverlayWindowPainter CustomPainter { get; set; }
vb
Public Property CustomPainter As IOverlayWindowPainter

Property Value

TypeDescription
DevExpress.XtraSplashScreen.IOverlayWindowPainter

An object that implements a custom paint logic.

|

Property Paths

You can access this nested property as listed below:

LibraryObject TypePath to CustomPainter
WinForms ControlsOverlayWindowOptions

.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.

csharp
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);
        }
    }
}
vb
Imports DevExpress.Utils.Drawing
Imports DevExpress.XtraEditors
Imports DevExpress.XtraSplashScreen
Imports System
Imports System.Drawing
Imports System.Threading.Tasks

Namespace DXOverlayFormDemo
    Public Partial Class Form1
        Inherits XtraForm

        Public Sub New()
            InitializeComponent()
            AddHandler Me.Load, AddressOf MainForm_Load
        End Sub

        Private Async Sub MainForm_Load(sender As Object, e As EventArgs)
            Dim handle As IOverlaySplashScreenHandle = Nothing
            Try
                handle = SplashScreenManager.ShowOverlayForm(Me, customPainter:=New CustomOverlayPainter())
                ' Emulate a long-running operation (5 seconds)
                Await Task.Delay(5000)
            Finally
                If handle IsNot Nothing Then
                    SplashScreenManager.CloseOverlayForm(handle)
                End If
            End Try
        End Sub
    End Class

    Public Class CustomOverlayPainter
        Inherits OverlayWindowPainterBase

        Private Shared ReadOnly drawFont As Font

        Shared Sub New()
            drawFont = New Font("Tahoma", 14)
        End Sub

        Protected Overrides Sub Draw(context As OverlayWindowCustomDrawContext)
            ' Set Handled to true to disable the default drawing.
            context.Handled = True

            ' Access the drawing surface.
            Dim cache As GraphicsCache = context.DrawArgs.Cache

            ' Improve text rendering quality.
            cache.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias

            ' Get the bounds of the overlapped control.
            Dim bounds As Rectangle = context.DrawArgs.Bounds

            ' Draw the default background.
            context.DrawBackground()

            ' Specify the message to display on the Overlay Form.
            Dim drawString As String = "Loading..."

            ' Use the system black brush for drawing text.
            Dim drawBrush As Brush = Brushes.Black

            ' Calculate the size of the text string.
            Dim textSize As SizeF = cache.CalcTextSize(drawString, drawFont)

            ' Determine the upper-left corner for centered text.
            Dim drawPoint As 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)
        End Sub
    End Class
End Namespace

See Also

OverlayWindowOptions Class

OverlayWindowOptions Members

DevExpress.XtraSplashScreen Namespace