NEWS

[DEVEXPRESS] Hướng dẫn tạo hiệu ứng form overlay in csharp

[DEVEXPRESS] Hướng dẫn tạo hiệu ứng form overlay in csharp
Đăng bởi: Thảo Meo - Lượt xem: 4508 14:30:18, 06/06/2019DEVEXPRESS   In bài viết

Xin chào các bạn, bài viết hôm nay mình sẽ tiếp tục hướng dẫn các bạn cách tạo hiệu ứng overlay trên panel winform C# sử dụng Devexpress.

[DEVEXPRESS] OVERLAY PANEL C#

Trong bài viết hôm trước bên chuyên mục mình đã có viết bài hướng dẫn các bạn cách tạo hiệu ứng làm mờ (blur) trong lập trình C#.

Bài hôm nay, mình sẽ hướng dẫn các bạn sử dụng SplashScreenManager để tạo hiệu ứng overlay cho winform.

Các bạn có thể theo dõi demo ứng dụng bên dưới để biết bài viết này mình viết về các gì:

overlay_csharp_devexpress

Thường chức năng này các bạn sẽ ứng dụng để khóa nguyên vùng panel.

Đầu tiên các bạn tạo cho mình một class: CustomOverlayWindowPainter.cs

using System.Drawing;

using DevExpress.Utils.Drawing;
using DevExpress.XtraSplashScreen;

namespace TestProject
{

    public class CustomOverlayWindowPainter : OverlayWindowPainterBase
    {  
      

        private static readonly Font _font;   
       
        static CustomOverlayWindowPainter()
        {
            _font = new Font("Tahoma", 16, FontStyle.Bold);
        }

     

       
        protected override void Draw(OverlayWindowCustomDrawContext context)
        {
            context.Handled = true;

            GraphicsCache cache = context.DrawArgs.Cache;

            cache.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
            

            Rectangle boundRectangle = context.DrawArgs.Bounds;

            context.DrawBackground();

            string message = "OVERLAY PANEL C# - HTTPS://LAPTRINHVB.NET";

            SizeF textSize = cache.Graphics.MeasureString(message, _font);

            PointF point = new PointF
            (
                (boundRectangle.Width  - textSize.Width ) / 2,
                (boundRectangle.Height - textSize.Height) / 2
            );

            cache.Graphics.DrawString(message, _font, Brushes.Orange, point);
        }

       
    }
}

 

Và source code C# cho MainForm.cs:

using System;

using DevExpress.XtraEditors;
using DevExpress.XtraSplashScreen;

namespace TestProject
{
    public partial class MainForm : XtraForm
    {

        public IOverlaySplashScreenHandle handle = null;


        public MainForm()
        {
            InitializeComponent();              
        }


        private void applyButton_Click(object sender, EventArgs e)
        {
        

            handle = SplashScreenManager.ShowOverlayForm(this.panel1, customPainter: new CustomOverlayWindowPainter());

        }



        private void cancelButton_Click(object sender, EventArgs e)
        {


            if (handle != null)
            {
                SplashScreenManager.CloseOverlayForm(handle);
            }


        }

    }
}

 

Thanks for watching!

DOWNLOAD SOURCE

Tags:

THÔNG TIN TÁC GIẢ

BÀI VIẾT LIÊN QUAN

[DEVEXPRESS] Hướng dẫn tạo hiệu ứng form overlay in csharp
Đăng bởi: Thảo Meo - Lượt xem: 4508 14:30:18, 06/06/2019DEVEXPRESS   In bài viết

CÁC BÀI CÙNG CHỦ ĐỀ

Đọc tiếp
.