PictureBox in C#

Posted on 2006-06-04
Last Modified: 2013-12-26
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

Question by:huy302
    LVL 18

    Accepted Solution


    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);

    LVL 2

    Assisted Solution

    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):


    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.
    LVL 5

    Expert Comment

    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.

    Expert Comment

    i want to get path of image from picturebox

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    What is RenderMan: RenderMan is a not any particular piece of software. RenderMan is an industry standard, defining set of rules that any rendering software should use, to be RenderMan-compliant. Pixar's RenderMan is a flagship implementation of …
    Artificial Intelligence comes in many forms, and for game developers, Path-Finding is an important ability for making an NPC (Non-Playable Character) maneuver through terrain.  A* is a particularly easy way to approach it.  I’ll start with the algor…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now