Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace TestApp
- {
- public partial class TestForm
- {
- private BufferedGraphics graphicsBuffer;
- private BufferedGraphicsContext bufferContext = BufferedGraphicsManager.Current;
- public TestForm()
- {
- InitializeComponent();
- UpdateGraphicsBuffer();
- }
- private void UpdateGraphicsBuffer()
- {
- bufferContext.MaximumBuffer = new Size(panelRender.Width + 1, panelRender.Height + 1);
- graphicsBuffer = bufferContext.Allocate(Graphics.FromHwnd(panelRender.Handle), new Rectangle(49, 49, 100, 100));
- graphicsBuffer.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
- }
- private void TestForm_Load(object sender, EventArgs e)
- {
- graphicsBuffer.Graphics.DrawRectangle(new Pen(Color.Red), 50, 50, 50, 50);
- }
- }
- }
- using System.Drawing;
- using System.Windows.Forms;
- namespace DoubleBufferTest
- {
- public partial class Form1 : Form
- {
- private BufferedGraphics graphicsBuffer = null;
- private BufferedGraphicsContext bufferContext = BufferedGraphicsManager.Current;
- public Form1()
- {
- this.SetStyle(ControlStyles.SupportsTransparentBackColor | ControlStyles.UserPaint, true);
- this.UpdateStyles();
- InitializeComponent();
- UpdateGraphicsBuffer();
- }
- private void UpdateGraphicsBuffer()
- {
- bufferContext.MaximumBuffer = new Size(panel1.Width + 1, panel1.Height + 1);
- graphicsBuffer = bufferContext.Allocate(Graphics.FromHwnd(panel1.Handle), new Rectangle(10, 10, 50, 50));
- }
- protected override void OnPaint(PaintEventArgs e)
- {
- base.OnPaint(e);
- graphicsBuffer.Graphics.DrawRectangle(new Pen(Color.Red, 3.0f), 20, 20, 10, 10);
- graphicsBuffer.Render();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement