Creating an application that uses a picture box as a target
Creating an application that uses a picture box as a target
Creating an application that uses a picture box as a target
Creating an application that uses a picture box as a target
Creating an application that uses a picture box as a target
Creating an application that uses a picture box as a target Creating an application that uses a picture box as a target Creating an application that uses a picture box as a target Creating an application that uses a picture box as a target Creating an application that uses a picture box as a target Creating an application that uses a picture box as a target Creating an application that uses a picture box as a target Creating an application that uses a picture box as a target
Creating an application that uses a picture box as a target Creating an application that uses a picture box as a target
Creating an application that uses a picture box as a target
Go Back  Xtreme Visual Basic Talk > > > Creating an application that uses a picture box as a target


Reply
 
Thread Tools Display Modes
  #1  
Old 05-25-2009, 10:01 AM
legend1990 legend1990 is offline
Newcomer
 
Join Date: May 2009
Posts: 2
Default Creating an application that uses a picture box as a target


I am trying to create an application were a image box moves around randomly until clicked on. The target then has to reappear in a random position but will be harder to hit by reducing the time allowed and speeding up the movement.

I am new to programming and am not sure how to do this.
Any help would be appreciated.
Reply With Quote
  #2  
Old 05-25-2009, 06:23 PM
Euroclydon's Avatar
Euroclydon Euroclydon is offline
Regular
 
Join Date: May 2009
Location: Northern Indiana, USA
Posts: 70
Default

I'm hoping you have a copy of the Language Reference. If so, try looking through the following keywords...

Move, Left, Top, Rnd

If you need something more specific, let me know.

When you say you want the image to move randomly, do you mean smooth movement, or "blinking" to new locations?
__________________
"Have a place for everything and keep the thing somewhere else; this is not a piece of advice, it is merely a custom." - Mark Twain
Reply With Quote
  #3  
Old 05-25-2009, 06:44 PM
legend1990 legend1990 is offline
Newcomer
 
Join Date: May 2009
Posts: 2
Default

To be honest with you i am completely new to this and do not know much.
I am using Microsoft Excel Visual Basic Editor and am not sure what to do.
The image has to move smoothly but speed up after every hit.

It is for an assignment but it something i am not familiar with.
Reply With Quote
  #4  
Old 05-26-2009, 03:05 AM
tpaksu's Avatar
tpaksu tpaksu is offline
Centurion
 
Join Date: Dec 2008
Location: Istanbul
Posts: 173
Default

place a picturebox and a timer inside a picturebox and then on the inner picturebox's click event, decrease the interval of the timer. In the timer's timer event, place the random movement code.
__________________
Never send a human to do a machine's job. (Agent Smith :P)
Reply With Quote
  #5  
Old 05-28-2009, 02:26 PM
Flamespewer Flamespewer is offline
Freshman
 
Join Date: Sep 2008
Posts: 35
Default

this is the basic code to do what you want. just make an image box and call it "Target" and a timer. every time you click the "Target" the timer gets faster and faster
the timer randomly generates the Targets top and left value using the "Rnd" function. you have to put int() around it because you only want whole numbers, no decimals.
Code:

Private Sub Form_Load()
    Timer1.Interval = 1000 'set the initial timer interval 1000 being 1 second
End Sub

Private Sub Target_Click()
    Timer1.Interval = Timer1.Interval - 100 'decrease timer interval= increase speed of random number generation
End Sub

Private Sub Timer1_Timer()
    Target.Left = Int(Rnd * Form1.Width) 'random left value
    Target.Top = Int(Rnd * Form1.Height) 'random top value
End Sub
Reply With Quote
  #6  
Old 05-29-2009, 02:48 PM
Euroclydon's Avatar
Euroclydon Euroclydon is offline
Regular
 
Join Date: May 2009
Location: Northern Indiana, USA
Posts: 70
Default

Of course, some verification will be needed when you subtract from the timer's interval, so it won't go below a certain point. Otherwise you end up with 0 - a non-functioning timer.

Or you could simply hide the target when Interval = 0, and display some kind of "well done" message.

You should also subtract the target's width/height from the form's so you don't end up with a partially (or almost entirely) hidden target.
Use the form's ScaleWidth/ScaleHeight to keep it actually inside the form.

(Apologies to Flamespewer, don't mean to sound picky. )

It's an unfortunate fact of programming that computers are not as smart as we at first think. You have to tell them everything you want, in detail. That means things get more complex, which opens the door to more problems!

Weeding out bugs (I know, mixed metaphor - sorry) will probably take up as much of your time as writing out the legit code. Just try not to become frustrated, and remember that no matter what your problem is, there's probably someone around who knows how to fix it.

Just be glad you're using VB and not C.
__________________
"Have a place for everything and keep the thing somewhere else; this is not a piece of advice, it is merely a custom." - Mark Twain
Reply With Quote
  #7  
Old 05-29-2009, 04:16 PM
Flamespewer Flamespewer is offline
Freshman
 
Join Date: Sep 2008
Posts: 35
Default

you are right, but this was just an example code so i didnt bother doing anything too complex.

and its almost impossible to get the timer less than 300 since it starts jumping like crazy
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Creating an application that uses a picture box as a target
Creating an application that uses a picture box as a target
Creating an application that uses a picture box as a target Creating an application that uses a picture box as a target
Creating an application that uses a picture box as a target
Creating an application that uses a picture box as a target
Creating an application that uses a picture box as a target Creating an application that uses a picture box as a target Creating an application that uses a picture box as a target Creating an application that uses a picture box as a target Creating an application that uses a picture box as a target Creating an application that uses a picture box as a target Creating an application that uses a picture box as a target
Creating an application that uses a picture box as a target
Creating an application that uses a picture box as a target
 
Creating an application that uses a picture box as a target
Creating an application that uses a picture box as a target
 
-->