Results 1 to 3 of 3

Thread: [1.1] Add multiple images in a single picturebox

  1. #1

    Thread Starter
    Addicted Member Kal-El's Avatar
    Join Date
    Jun 2007
    Location
    Fortress of solitude
    Posts
    179

    [1.1] Add multiple images in a single picturebox

    Hi all!

    I have this load an image to a picturebox:
    csharp Code:
    1. private void onLoadImages(object sender, System.EventArgs e)
    2.         {
    3.             OpenFileDialog ofd = new OpenFileDialog();
    4.             ofd.InitialDirectory = System.Environment.CurrentDirectory;
    5.             ofd.Filter = "Icons (*.ico)|*.ico|BMPs (*.bmp)|*.bmp|GIFs (*.gif)|*.gif|JPEGs (*.jp*)|*.jp*|PNGs (*.png)|*.png";
    6.             if (ofd.ShowDialog(this) != DialogResult.Cancel)
    7.             {
    8.                 Image img = Image.FromFile(ofd.FileName);
    9.                 this.pictureBox1.Image = new Bitmap(img, new Size(32, 32));
    10.             }
    11.         }
    But this, as you may know..replace the old image...I want to make like a imagelist viewer, so the the image will be next to another...any ideas?

    «Source Code»«plugins»«skin»«fav apps»«Winamp en español»«Nsis en español»
    So what if your signature move is driving a tractor? I think it's adorable. - Lois ("Crimson")
    Don't forget to when your question is resolved ...and the people who help

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [1.1] Add multiple images in a single picturebox

    It's not possible to display more than one Image in a PictureBox. You can either use multiple PictureBoxes to display one Image each, or else combine all your individual images into a single Image object and display that in a single PictureBox. I'd be inclined to go with the first option.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    New Member
    Join Date
    Sep 2007
    Posts
    1

    Re: [1.1] Add multiple images in a single picturebox

    Actually it IS possible to put more than one image in a picturebox. But only two ... backgroundimage and image if you use the properties.

    So here's what you have to do to put MORE THAN ONE image in a picturebox control.

    Code:
    Bitmap BG1 = new Bitmap(BMP_FileName);
    Bitmap BG2 = new Bitmap(BMP_FileName);
    Bitmap BG3 = new Bitmap(BMP_FileName);
    Bitmap BG4 = new Bitmap(BMP_FileName);
            
    // overwrite paint
    private void PictureBox_Paint(object sender, PaintEventArgs e)
    {
                // Create Point for upper-left corner of image1.
                if (BG1 != null)
                {
                    Point P1 = new Point(0, 0);
                    e.Graphics.DrawImage(BG1, P1);
                }
                if (BG2 != null)
                {
                    Point P2 = new Point(0, 64);
                    e.Graphics.DrawImage(BG2, P2);
                }
                if (BG3 != null)
                {
                    Point P3 = new Point(64, 0);
                    e.Graphics.DrawImage(BG3, P3);
                }
                if (BG4 != null)
                {
                    Point P4 = new Point(64, 64);
                    e.Graphics.DrawImage(BG4, P4);
                }
                //.... and so forth
    }
    Last edited by bobphrapples1414; Sep 20th, 2007 at 02:43 PM. Reason: found a solution

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width