using System;
      using System.Drawing;
      using System.Drawing.Drawing2D;
      using System.Collections;
      using System.ComponentModel;
      using System.Windows.Forms;
      using System.Data;
      using System.Drawing.Imaging;

      public class Program : System.Windows.Forms.Form
      {
        public Program()
        {
          Contoh1();

        }

        private void Contoh1()
        {
          this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
          System.Threading.Thread.Sleep(2000); 
          this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form2_Paint);
        }
        static void Main() 
        {
          Application.Run(new Program());
        }

        private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {    
           Graphics g = e.Graphics;
          Bitmap bmp = new Bitmap("D:/space.jpg");
          g.DrawImage(bmp, 0, 0);       
        }

        private void Form2_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {       
            Graphics g = e.Graphics;
          Bitmap bmp = new Bitmap("D:/space 2.jpg");
          g.DrawImage(bmp, 0, 0); 
        }

      }

The source code Can't show first picture then after 2 second the source code show second picture. And how to resolve my problem ? I want to understand why the codes in source code doesn't work.

Recommended Answers

All 8 Replies

Check the file path for your first image is correct. As far as I can see thats the only thing that might be causing the problem.

ChristHunter : if you copy this source code the problem is visible

No, explain your problem more, do you get an error? is the image transparent? is the image white? is it just a case of once the second image shows you can't see the first image anymore?.

If the latter is the case then replace the zeros in the g.DrawImage with other numbers as they are what sets the location of the image on the screen.

I can't see the first image.

If I replace the zeros. Two image is shown at same time! (After thread.sleep work)
I want first image appear then second image appear after 2 second

What it looks like you were orignally doing is putting the second picturebox over the first without setting it's visible property to false, meaning you can't see the first picturebox through the second. Set the visible property of both pictureboxes to false by default and then set them to true in turn.

Doesn't look like picture boxes are involved at all, instead painting directly on the form.

Also, you're giving the form multiple paint events. So everytime your form goes to pain, it will call all three (including the built-in one that draws all your controls)

The order these are called in, cannot be guaranteed.

You should redesign the entire thing to use picture boxes and an event to signal the second image to be drawn. Thread.Sleep will stop your application working for two seconds (including all the events)

You're more than welcome.

What was the issuse in the end?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.