Jump to content
  • Advertisement
Sign in to follow this  
Chris27

doublebuffered exception

This topic is 4029 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm getting an exception error when setting doublebuffered to true in C#. I'm not sure why it's happening. It says invalid argument exception.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace SimpleGame
{
    public partial class frmSimpleGame : Form
    {
        private Bitmap m_objDrawingSurface;
        private Graphics objGraphics;
        private SolidBrush solidBrush = new SolidBrush(Color.Black);
        
        public frmSimpleGame()
        {
            //this.DoubleBuffered = true;
            InitializeComponent();
        }

        private void frmSimpleGame_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.DrawImage(m_objDrawingSurface, 0, 0,
            m_objDrawingSurface.Width,
            m_objDrawingSurface.Height);
            e.Graphics.Dispose();
        }

        private void frmSimpleGame_Load(object sender, EventArgs e)
        {
            
            //this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            //this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            m_objDrawingSurface = new Bitmap(this.ClientSize.Width, this.ClientSize.Height,
                System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            objGraphics = Graphics.FromImage(m_objDrawingSurface);
            objGraphics.Clear(Color.Aqua);
        }

        private void frmSimpleGame_MouseMove(object sender, MouseEventArgs e)
        {

            
            objGraphics = Graphics.FromImage(m_objDrawingSurface);
            objGraphics.Clear(Color.Aqua);
            objGraphics.FillEllipse(solidBrush, e.X - 25, e.Y - 25, 50, 50);
            this.Invalidate();
            lblX.Text = string.Concat("X:" + (e.X - 25));
            lblY.Text = string.Concat("Y:" + (e.Y - 25));
        }

        private void frmSimpleGame_FormClosed(object sender, FormClosedEventArgs e)
        {
            solidBrush.Dispose();
            objGraphics.Dispose();
        }
    }
}

The project works fine if I take out doublebuffered = true. I've tried it in the load event. I've also tried using the setstyle method and it gives the same exception error. Thanks

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!