BufferedGraphicsContext 类

定义

提供创建图形缓冲区的方法,该缓冲区可用于双缓冲。

public ref class BufferedGraphicsContext sealed : IDisposable
public sealed class BufferedGraphicsContext : IDisposable
type BufferedGraphicsContext = class
    interface IDisposable
Public NotInheritable Class BufferedGraphicsContext
Implements IDisposable
继承
BufferedGraphicsContext
实现

示例

下面的代码示例演示如何获取 BufferedGraphicsContext 当前应用程序域。 此代码是为类提供的大型示例的 BufferedGraphics 一部分。

// Retrieves the BufferedGraphicsContext for the 
// current application domain.
BufferedGraphicsContext^ appDomainGraphicsContext =
   BufferedGraphicsManager::Current;
// Retrieves the BufferedGraphicsContext for the
// current application domain.
BufferedGraphicsContext appDomainGraphicsContext =
     BufferedGraphicsManager.Current;
' Retrieves the BufferedGraphicsContext for the 
' current application domain.
Dim appDomainGraphicsContext As BufferedGraphicsContext = BufferedGraphicsManager.Current

注解

BufferedGraphicsContext 类允许你为图形实现自定义双缓冲。 使用双缓冲的图形可以减少或消除由重绘显示图面引起的闪烁。

备注

在 .NET 6 及更高版本中,System.Drawing.Common包 (包括此类型)仅在 Windows操作系统上受支持。 在跨平台应用中使用此类型会导致编译时警告和运行时异常。 有关详细信息,请参阅仅支持System.Drawing.Common Windows。

备注

使用双缓冲的最简单方法是使用SetStyle该方法在控件上设置OptimizedDoubleBuffer控件样式标志。 为 OptimizedDoubleBuffer 控件设置控件样式标志会通过默认图形缓冲区重定向控件的所有绘制,而无需任何其他代码。 This flag is set to true by default.

BufferedGraphicsContext 类提供用于创建和配置图形缓冲区的方法。 该方法 Allocate 创建一个 BufferedGraphics,它是图形缓冲区的包装器,该包装器还提供可用于写入缓冲区的方法并将其内容呈现到输出设备。

可以从静态BufferedGraphicsManager.Current属性检索BufferedGraphicsContext当前应用程序域。 对于图形密集型应用程序(如动画),可以使用构造函数创建专用 BufferedGraphicsContext 应用程序,但对于大多数应用程序 BufferedGraphicsManager.Current ,该属性将足够。

有关绘制缓冲图形和自定义缓冲实现的详细信息,请参阅 双缓冲图形 以及如何 :手动管理缓冲图形

构造函数

BufferedGraphicsContext()

初始化 BufferedGraphicsContext 类的新实例。

属性

MaximumBuffer

获取或设置要使用的缓冲区的最大大小。

方法

Allocate(Graphics, Rectangle)

使用指定的 Graphics 的像素格式,创建指定大小的图形缓冲区。

Allocate(IntPtr, Rectangle)

使用指定的 Graphics 的像素格式,创建指定大小的图形缓冲区。

Dispose()

释放由 BufferedGraphicsContext 使用的所有资源。

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
Finalize()

在垃圾回收将某一对象回收前允许该对象尝试释放资源并执行其他清理操作。

GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
Invalidate()

如果某个缓冲区已被分配但尚未释放,则释放当前的图形缓冲区。

MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

适用于

另请参阅