troubleshooting Question

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

Avatar of chevronrod
chevronrodFlag for United States of America asked on
C#
2 Comments1 Solution635 ViewsLast Modified:
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!
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros