• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 34513
  • Last Modified:

PictureBox in C#

Hi everybody !
I am coding game project in C# ! When  I used PictureBox control to display image I get some problems.

this is my coding :

     
       this.mypictureBox.image = new Bitmap("test.gif");
       // I do sothing need a  lot of time
      ...............................................
       

when i am waiting for "do some thing" , Image in mypictureBox does not change. But I want it change.

So, Can someone help me to overcome that problem

thanks
   
0
huy302
Asked:
huy302
2 Solutions
 
Jose ParrotGraphics ExpertCommented:
Hi,

Below is how to display an image in a picture box.

private System.Windows.Forms.PictureBox pictbox;
string path = "test.gif";
pictbox.Image = new Bitmap(path);

This code show how to take the bitmap data:

Bitmap b = new Bitmap(path);
BitmapData bmData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height),
ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);

Jose
0
 
Jared_GCommented:
Insert this line of code right after the image is set in the picture box (and before you do the processing that takes so much time):

mypictureBox.Refresh();


This *should* force windows to re-draw the updated picture box right away.

I have done similar things in C# (basic games and such.) You will notice however as things get more complex with more pictures and movement that it really start to slow down. But for basic things your method of using picture boxes works fine.

I can help further if needed.
0
 
thegilbCommented:
A recommend your next project should use managed directx. It's really simple to use, there's some great books on it and it's tons faster.
0
 
samirnagarkarCommented:
i want to get path of image from picturebox
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now