doublebuffer.cs

来自「c#编写的仿OUTLOOK工具条的Winform菜单」· CS 代码 · 共 58 行

CS
58
字号
using System;
using System.Drawing;

namespace UtilityLibrary.WinControls
{
	/// <summary>
	/// Summary description for BitmapDoubleBuffer.
	/// </summary>
	public class DoubleBuffer
	{
		int bufferWidth;
		int bufferHeight;
		Bitmap surface;
		Graphics buffer;

		private void Cleanup() 
		{
			if (buffer != null) 
			{
				buffer.Dispose();
				buffer = null;
			}
			if (surface != null) 
			{
				surface.Dispose();
				surface = null;
			}
		}

		public Graphics RequestBuffer(int width, int height) 
		{
			if (width == bufferWidth && height == bufferHeight && buffer != null) 
			{
				return buffer;
			}

			Cleanup();
			surface = new Bitmap(width, height);
			buffer = Graphics.FromImage(surface);
			bufferWidth = width;
			bufferHeight = height;
			return buffer;
		}

		public void PaintBuffer(Graphics dest, int x, int y) 
		{
			dest.DrawImage(surface, x, y);
		}

		public void Dispose() 
		{
			Cleanup();
		}
		
	}
	
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?