| | |
Visual C++ 2008 - Random location picturebox?!?
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2008
Posts: 60
Reputation:
Solved Threads: 3
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.
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
Do you know how to move the window? MoveWindow() will do the trick.
Selecting a random number between 1 and 3 is easy --
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.
•
•
Join Date: Jul 2008
Posts: 60
Reputation:
Solved Threads: 3
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.

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
>You see, I'm trying to move the actual picturebox, not the window.
Just use the
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."
>>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.
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.
•
•
Join Date: Jul 2008
Posts: 60
Reputation:
Solved Threads: 3
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
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
>>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?
C++ Syntax (Toggle Plain Text)
#include <ctime> // for time() function int main() { // seed the random number generator srand( (unsigned int)time(0)); <snip> // somewhere in your program do something like this int nms[] = {70233, 204140, 4646}; int location = nms[ rand() %3]; }
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.
![]() |
Other Threads in the C++ Forum
- Previous Thread: c++ design problem
- Next Thread: Acessing indefinte arguments for a function?
| Thread Tools | Search this Thread |
api array beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion count data database delete desktop developer directshow dll download dynamic email encryption error file forms fstream function functions game getline google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text text-file tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets







