You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.9 KiB
C#

1 month ago
// ***********************************************************************
// Assembly : Construction
// Author : flythink
// Created : 07-02-2020
//
// Last Modified By : flythink
// Last Modified On : 09-01-2020
// ***********************************************************************
// <copyright file="XPaintHelper.cs" company="jindongfang">
// Copyright (c) jindongfang. All rights reserved.
// </copyright>
// <summary></summary>
// ***********************************************************************
namespace WellWorkDataUI
{
using DevExpress.Utils.Drawing;
using DevExpress.Utils.Paint;
using System;
/// <summary>
/// using自动切换XPaint
/// </summary>
public class XPaintHelper : IDisposable
{
private static ObjectPool<XPaintHelper> pool = new ObjectPool<XPaintHelper>(() => new XPaintHelper());
private GraphicsCache cache;
private XPaint newItem;
private XPaint oldItem;
private XPaintHelper()
{
}
/// <summary>
/// Switches the specified cache.
/// </summary>
/// <param name="cache">The cache.</param>
/// <param name="paint">The paint.</param>
/// <returns>XPaintHelper.</returns>
public static XPaintHelper Switch(GraphicsCache cache, XPaint paint)
{
XPaintHelper item = pool.Get();
item.cache = cache;
item.oldItem = cache.Paint;
item.newItem = paint;
cache.Paint = paint;
return item;
}
/// <summary>
/// Provides <see cref="T:Microsoft.Win32.RegistryKey" /> objects that represent the root keys in the Windows registry, and <see langword="static" /> methods to access key/value pairs.
/// </summary>
public void Dispose()
{
this.cache.Paint = this.oldItem;
pool.Return(this);
}
}
}