Jump to content

Problem displaying picture

- - - - -

  • Please log in to reply
No replies to this topic

#1
jackolantern

jackolantern

    Learning Programmer

  • Members
  • PipPipPip
  • 47 posts
Hello! I am working on a very small project, and think I have everything ok, except for one part. I have never had to pull up an image into a pictureBox programmatically before. I think I am just not adding the image to the project correctly, because VS2008 is complaining that the jpeg images are not in the current context. Here is the code I have (this is on a Click event on the only button on the forum. It is also a Windows Form project):

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;


namespace DiceRoll

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }


        private void button1_Click(object sender, EventArgs e)

        {

            Random rand = new Random();

            int randNumber = 0;

            randNumber = (rand.Next(5)) + 1;


            switch (randNumber)

            {

                case 1:

                    pictureBox1.Image = One.jpg;

                    break;

                case 2:

                    pictureBox1.Image = Two.jpg;

                    break;

                case 3:

                    pictureBox1.Image = Three.jpg;

                    break;

                case 4:

                    pictureBox1.Image = Four.jpg;

                    break;

                case 5:

                    pictureBox1.Image = Five.jpg;

                    break;

                case 6:

                    pictureBox1.Image = Six.jpg;

                    break;

                default:

                    MessageBox.Show("An error occured!");

                    break;

            }

        }

    }

}

I followed the closest instructions I could find to add the images to the project, which was to Right-click >> ADD to the project >> Add existing >> then I selected the images and added them.

Any help would be greatly appreciated! Thank you :)




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users