Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Project Resource

Project Resource

Scheduled Pinned Locked Moved C#
helpquestionlearning
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mihksoft
    wrote on last edited by
    #1

    Hy, I have 3 pictures in a project resource, a picturebox and a button. I want when I press the button to change dynamic the pictures from picturebox. Can anybody help me? thx

    J 1 Reply Last reply
    0
    • M mihksoft

      Hy, I have 3 pictures in a project resource, a picturebox and a button. I want when I press the button to change dynamic the pictures from picturebox. Can anybody help me? thx

      J Offline
      J Offline
      Justin Perez
      wrote on last edited by
      #2

      Sure, we woyld love to help. Where are you at on the task right now? Where are you stuck at?

      I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")

      M 1 Reply Last reply
      0
      • J Justin Perez

        Sure, we woyld love to help. Where are you at on the task right now? Where are you stuck at?

        I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")

        M Offline
        M Offline
        mihksoft
        wrote on last edited by
        #3

        It's not a task is for my knowledge. I want to place random image from the project resource to my picturebox.that's it :D

        K 1 Reply Last reply
        0
        • M mihksoft

          It's not a task is for my knowledge. I want to place random image from the project resource to my picturebox.that's it :D

          K Offline
          K Offline
          Kristian Sixhoj
          wrote on last edited by
          #4

          Create an array, and put the images from the project resource in it.

          // 5 means there are five images. Change it if you need to.
          Image[] images = new Image[5];

          Then create an object of type System.Random:

          Random ran = new Random();

          ^ These two must be defined outside a method. Then do the following in your button event handler:

          // fill the array with images
          images[0] = Properties.Resources.Image1; // Image1 is the name of the image
          images[1] = Properties.Resources.Image2;
          images[2] = Properties.Resources.Image3;
          images[3] = Properties.Resources.Image4;
          images[4] = Properties.Resources.Image5;

          // generate a random integer below 5
          int pic = ran.Next(5);

          pictureBox1.Image = images[pic];

          And that should do the trick. Edit: Perhaps it would be better to fill up the array in the form's constructor (usually public Form1()):

          public Form1()
          {
          InitializeComponent();
          images[0] = Properties.Resources.Image1;
          images[1] = Properties.Resources.Image2;
          // and so on..
          }

          Virtual1ty


          "Any fool can learn from his own mistakes, but a wise man learns from mistakes of others"

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups