Link to home
Start Free TrialLog in
Avatar of chevronrod
chevronrodFlag for United States of America

asked on

Double buffering produces 'PARAMETER NOT VALID' in Program code.

I'm trying to double buffer a form. I want to draw a bitmap on it for now. My goal is to get several bitmaps all moving around on the screen: that's why i want the double buffering.

IT WORKS ABSOLUTELY PERFECTLY without the Double Buffering.

When I set the Double Buffering property of the form, I get the error listed at the bottom fo this description.

I've set the form's Double Buffering property to true. Here is the code for the form. It's pretty simple right now as I test this:
----------------------------------------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            using (Graphics objGraphics = e.Graphics)
            {

                System.Reflection.Assembly thisExe;
                thisExe = System.Reflection.Assembly.GetExecutingAssembly();
                System.IO.Stream file = thisExe.GetManifestResourceStream("WindowsApplication1.Resources.L.png");
                Size size = new Size(40, 40);
                Bitmap newbitmap = new Bitmap(Image.FromStream(file), size);

                e.Graphics.DrawImage(newbitmap, new Point(40, 40));

                //Dispose of the image files.
                newbitmap.Dispose();

            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}
-----------------------------------------------------------------------------------------------------------------------------
Here is the Program code.

using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace WindowsApplication1
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}
--------------------------------------------------------------------------------------------------------------------------
When I run the program with Double Buffering set to true I get this error on the line above that says, "Application.Run(new Form1());"  :

PARAMETER IS NOT VALID.

---------------------------------------------------------------------------------------------------------------------------
Any ideas? Why am I doing what I am doing in the code? I don't know. I've found trying to get bitmaps with transparent backgrounds to work and this finally does it. So I'm really happy with THAT. If the DB worked, I'd be ecstatic!
ASKER CERTIFIED SOLUTION
Avatar of andrewbleakley
andrewbleakley
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of chevronrod

ASKER

Sure solved my problem! Fantastico! Thank you.