Visual C++ 2008 - Random location picturebox?!?

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2008
Posts: 60
Reputation: Wiki_Tiki is an unknown quantity at this point 
Solved Threads: 3
Wiki_Tiki Wiki_Tiki is offline Offline
Junior Poster in Training

Visual C++ 2008 - Random location picturebox?!?

 
0
  #1
Aug 18th, 2008
Hello everyone,

I need help with a program I'm busy working on. I've created a test application, and I need it to move one pictureBox control (pictureBox1) to move to a random location (either 70,233 or 204,146 or 46,46) each time a button (button1) is clicked. Take note again that one of 3 locations should be randomly selected, each time the button's clicked.

I've seriously, for the life of me, been trying to work on this for half a month. I've tried many codes including rand(), so and so but nothings working.

If anyone could give me a hand, it would be very much appreciated.

Thanks in advance.
- The C++ fatal n00b
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,401
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1467
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Visual C++ 2008 - Random location picturebox?!?

 
0
  #2
Aug 19th, 2008
Do you know how to move the window? MoveWindow() will do the trick.

Selecting a random number between 1 and 3 is easy -- int n = (rand()%3) + 1
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 60
Reputation: Wiki_Tiki is an unknown quantity at this point 
Solved Threads: 3
Wiki_Tiki Wiki_Tiki is offline Offline
Junior Poster in Training

Re: Visual C++ 2008 - Random location picturebox?!?

 
0
  #3
Aug 19th, 2008
Thanks ancientdragon for your time, but I think maybe I didn't describe well enough
You see, I'm trying to move the actual picturebox, not the window. The random part is the computer selecting randomly one of the three locations I specified earlier, and then moving the picturebox to that randomly selected location of the three.
- The C++ fatal n00b
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 5,051
Reputation: John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold 
Solved Threads: 332
Team Colleague
John A's Avatar
John A John A is offline Offline
Vampirical Lurker

Re: Visual C++ 2008 - Random location picturebox?!?

 
1
  #4
Aug 19th, 2008
>You see, I'm trying to move the actual picturebox, not the window.
Just use the PictureBox::Location data member (remember, System.Windows.Forms.PictureBox is inherited from the System.Windows.Forms.Control class). Selecting one of three locations is easy -- use AD's random number generator example and run it through a switch or if else statement.
"Technological progress is like an axe in the hands of a pathological criminal."
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,401
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1467
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Visual C++ 2008 - Random location picturebox?!?

 
0
  #5
Aug 19th, 2008
>>You see, I'm trying to move the actual picturebox, not the window
Everything is treated as a window -- combobox, listbox, picturebox, buttons, checkboxes -- all those are windows.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 60
Reputation: Wiki_Tiki is an unknown quantity at this point 
Solved Threads: 3
Wiki_Tiki Wiki_Tiki is offline Offline
Junior Poster in Training

Re: Visual C++ 2008 - Random location picturebox?!?

 
0
  #6
Aug 20th, 2008
Thanks again, but yes, I know how to move the picturebox with the Picturebox1::Location.

I'm just a total noob, and am having trouble putting the suggestions into the correct code. I tried saying (rand()%3) but the only number I get is 3, nothing else at all.

Is there any way of giving an example of putting all the suggestions together? once again, I'm a total noob.

Take note that this isn't homework, It's a game I'm busy working on.

And one more thing:
>>use AD's random number generator example and run it through a switch or if else statement.

How would I do this? How to I tell the random generator to only put the location in 70,233, 204,146 or 46,46?

Please try to give me something a bit simpler to understand
- The C++ fatal n00b
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,401
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1467
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Visual C++ 2008 - Random location picturebox?!?

 
0
  #7
Aug 20th, 2008
>>How would I do this? How to I tell the random generator to only put the location in 70,233, 204,146 or 46,46?

  1. #include <ctime> // for time() function
  2. int main()
  3. {
  4. // seed the random number generator
  5. srand( (unsigned int)time(0));
  6. <snip>
  7. // somewhere in your program do something like this
  8. int nms[] = {70233, 204140, 4646};
  9. int location = nms[ rand() %3];
  10. }
Last edited by Ancient Dragon; Aug 20th, 2008 at 6:06 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 60
Reputation: Wiki_Tiki is an unknown quantity at this point 
Solved Threads: 3
Wiki_Tiki Wiki_Tiki is offline Offline
Junior Poster in Training

Re: Visual C++ 2008 - Random location picturebox?!?

 
0
  #8
Aug 20th, 2008
Thanks ancientdragon, now I know what you mean

Sorry, I must've sounded like such a retard

I've added to your reputation, thanks again for your help
- The C++ fatal n00b
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC