Hi, guys, I'm programming some artificial intelligence for a graphics program, Graphics Gale. The program is horrible, it won't let me combine layers with the same name, and it won't let me save the image as a Photoshop file, so what do I have to do? I have to code some AI. I have around 260 images that i need the layers combined, so I got all the AI working except for one part that makes no sence what so ever. It copies the current layer's image to the clipboard, and then saves it to a specified folder, but I cannot get the clipboard copying to work. I do the SendKeys function to copy the image to the clipboard, then make an image variable with the clipboard image( Clipboard.GetImage() ). It sometimes says it can't open the clipboard, and then other times it says it has a image, but it's null, then othertimes the variable shows my previous clipboard. Anyways, here's my code for getting the image.

        //SendKeys with sleep just incase the thing wasn't working because it was too fast.
        public void SendText(string text)

        public void GetImage()
            //clears the clipboard, because many times it would set it to my old clipboard image

            //makes sure the program's canvas is selected, then copies the image via cut and paste

            //the code that doesn't work.
            pictureBox1.Image = Clipboard.GetImage();

        private void timer1_Tick(object sender, EventArgs e)
            //if i press the middle mouse button, then it calls the AI function.
            if (GetAsyncKeyState(4) == -32767)

Are you making sure the image in the program has focus?


I'm really sure that it does have focus, because I first press the middle mouse key in Graphics Gale window, then it sends the escape key, just incase there was something blocking the canvas and it then cut and pastes it, and I can see it doing it, so yeah, it is focused. Not only that, but I can paste my clipboard to Graphics Gale, and the image is what the AI cut, but it still doesn't show in the picturebox.

In short, yes, I'm positive it's focused.

How is your picture stored that you're pasting from?

Perhaps there's a timelag, you could try a loop checking for clipboard.Containsimage()

Have you redrawn/refreshed the Picture box you're pasting into?

I have tried refreshing it, and the form itself, and in both cases it doesn't change anything. I'll upload a video showing the problem soon.

Did you try the loop suggestion?