that depends on how you are drawing your images. If you have them in a pictuerbox then you need to move the picturebox. If you are painting them to a control then you need to adjust the x,y values of the point where you draw the image.
As for drawing a random image on timer, you need to look into random number generator, give each image a number, then on the timer tick event, generate a random number and paint the relevant image.
Ryshad
Nearly a Posting Virtuoso
1,307 posts since Aug 2009
Reputation Points: 512
Solved Threads: 246
I already gave you an example snippet in a previous thread.
Perhaps it was to complicated I don't know. Did you study it?
Give you a new simpler example here:
Create a new windowsformsapp and drop a Panel on it, then fill in this code in the Forms1.cs file.
using System;
using System.Drawing;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
const int cTimerInterval = 25; // millisecs
const int cBallSize = 16;
Bitmap bm;
Point pt;
Timer clock;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// start a timer and install the tick event
clock = new Timer();
clock.Interval = cTimerInterval;
clock.Tick += new EventHandler(clock_Tick);
clock.Start();
pt.X = 0;
pt.Y = 0;
// create bitmap or get one from a file or resourcefile
bm = new Bitmap(cBallSize, cBallSize);
Graphics gr = Graphics.FromImage(bm);
gr.Clear(BackColor);
gr.FillEllipse(Brushes.Red, pt.X, pt.Y, cBallSize, cBallSize);
gr.Dispose();
}
void clock_Tick(object sender, EventArgs e)
{
// we come here every 25 millisecs
pt.X += 1;
pt.Y += 1; //increment position
// for simplicity we generate an update of the whole window
// this causes the paint event of the panel to happen
this.Refresh();
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
//draw the bitmap at position pt
e.Graphics.DrawImage(bm, pt);
}
}
}
Generate the form load event by double clicking the form in design mode, the panel paint event is also generated by double clicking.
This will only work if you have an uniform background.
ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
No this is far from correct, but don't panic.
int [] pic = new int [1];
This means create an array named pic with 1 element. You can call this with pic[0] (arrays start at index 0) pic[1] would give an index out of range exception.
You cannot use int.Parse on a jpg file(would also give some exception)
I would advise you to use my example.
On line 51, instead of bm, fill in one of your file paths and see what happens.
ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
Of course my example is not what you want, but did you try it? Did you experiment with different values for the Point variable?
Do this in lines 41 and 42. You can use a random method here to put your images anywere on the screen.
Change this Point variable in a KeyDown event for your arrow buttons etc. Experiment! See what happens, you will learn from it believe me.
ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
are the 2 pictures that appear randomly going to be in the same place every time they appear? if so you could just place pictureboxes with the images in them and hide/show them based on a random number generator.
Also, cant stress ddanbe's point enough. It is so important to experiment with code. Its the best way to learn how it works. Figure out what its doing and try to work out what you need to change to make it do what you need.
Ryshad
Nearly a Posting Virtuoso
1,307 posts since Aug 2009
Reputation Points: 512
Solved Threads: 246
You seem to constantly ignore the advise we give you.
Did or did you not try out the code I gave you?
Do you expect we give you the code you want to have?
I don't have to type this in, I don't have to do this at all.
I do this because I'm a learner myself (learned alot here already) and I like, if possible, that others can benefit from my knowlege.
So, please show some effort, try something for yourself and if does not work, show us your code. Please?:icon_smile:
ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661