User Login

Help Community Login:

Mouse move event

17 replies [Last post]
Evil Monkey's picture
Evil Monkey
Moderator (Watching Over The Masses)Premium Member (Silver)The Steel CurtainI use FirefoxI use Google ChromeI use Internet ExplorerI use SafariI'm Here To Help, & Have Proven It!Windows UserMember of VileThe JokerSomeone thinks you're a Rotten Tomato!STaRDoGG <3's you ;)
Joined: 01/22/2009
Posts: 234
Drops: 350

I'm working on writing a small 10 question quiz program. What I am trying to do in one of the questions is make it so only one out of the two possible answers will not be clickable. What I mean is when the user get's near the one check box it moves away from the mouse and will not allow you to select it. I"m thinking it's possible to do this with the mouse move event but im not sure how exactly to do write it.

I have done something like this with the mouse hover event. Basically I created like 4 separate instances of the same check box and positioned them around my form. I set all but the default box to invisible. Then using mouse hover I set the first one to invisible and the next one to visible, and so on. It works but not exactly what i was going after. I want the user to be able to chase the box all over the form or even off the form. I can't seem to find anything on doing this. I've searched and searched but keep coming up with nothing.

I Averaged: 0 | 0 votes


Read More ...





Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
STaRDoGG's picture
From:
Olympus
STaRDoGG
Head Mucky MuckJoined the Dark SidePremium Member (Gold)I'm a Code Monkey!The Steel CurtainI use FirefoxI use Google ChromeI use Internet ExplorerI use SafariLinux UserMac UserWindows UserI donated to GeekDrop simply because I love it!Booga Booga BoogaI took a bite of the AppleFormer Phrozen Crew MemberI'm MagicMember of VileThe Dr. put the stem on the apple!The JokerSomeone thinks you're udderly delightful!
Relationship Status:
Divorced
Joined: 01/14/2009
Posts: 2551
Drops: 2998
Mood: Curious
Re: Mouse move event

Mouse Hover is the right event to use, but instead of making multiple checkbox objects for that one, use the same checkbox (less objects also means less overhead/memory used), but make a random number generator to generate a new X and Y Location for the checkbox object when the mouse hovers over it.

I wrote a little random number generator a while ago, you can use for starters, you may want to change the variable types to Single, Double, etc.

' Initialize random number generator
Dim r As New Random(System.DateTime.Now.Millisecond)
 
Public Function GenerateRandomNumber(ByVal intMin As Integer, ByVal intMax As Integer) As Integer
 
    GenerateRandomNumber = 0
    Return r.Next(intMin, intMax)
 
  End Function

Also, be careful to make sure the number you use as new coordinates doesn't go off the form, or outside of whatever container it's in (like a groupbox or something), you'll probably get an error. Index out of bounds, or similar. If it's only the Form as the container, you can use me.width, me.height, etc.


Never play leapfrog with a unicorn
Evil Monkey's picture
Evil Monkey
Moderator (Watching Over The Masses)Premium Member (Silver)The Steel CurtainI use FirefoxI use Google ChromeI use Internet ExplorerI use SafariI'm Here To Help, & Have Proven It!Windows UserMember of VileThe JokerSomeone thinks you're a Rotten Tomato!STaRDoGG <3's you ;)
Joined: 01/22/2009
Posts: 234
Drops: 350
Re: Mouse move event

So how would I plug that code into my form? right into the checkbox code itself?

just looking at it would I do something along these lines?

' Initialize random number generator
Dim r As New Random(System.DateTime.Now.Millisecond)
 
Public Function GenerateRandomNumber(ByVal SingleX As Single, ByVal DoubleY As Double) As Double
 
    GenerateRandomNumber = 0
    Return r.Next(singleX, doubleY)
 
  End Function

--
I hope that after I die, people will say of me: "That guy sure owed me a lot of money.''

STaRDoGG's picture
From:
Olympus
STaRDoGG
Head Mucky MuckJoined the Dark SidePremium Member (Gold)I'm a Code Monkey!The Steel CurtainI use FirefoxI use Google ChromeI use Internet ExplorerI use SafariLinux UserMac UserWindows UserI donated to GeekDrop simply because I love it!Booga Booga BoogaI took a bite of the AppleFormer Phrozen Crew MemberI'm MagicMember of VileThe Dr. put the stem on the apple!The JokerSomeone thinks you're udderly delightful!
Relationship Status:
Divorced
Joined: 01/14/2009
Posts: 2551
Drops: 2998
Mood: Curious
Re: Mouse move event

You don't really need ot change the variable names in that code snippet. The intMin = the minimum number to pass to the random number function, and the intMax is the maximum number to pass. If you were to change the type of variable to pass/return you would just change the parts that say 'integer', and you should keep them the same type for this particular thing, since the X & Y coordinates use the same type of variable.

You could either add all the code in a separate module, or since you're just making a real small app, just add it all into the main form. Put the Dim r stuff at the top in the Declarations section, and then the rest of the original code I pasted anywhere else in the main form's code. It's just a function you're going to be calling to generate the random numbers for you.

Then in the mouse hover event, do someth9ing along the lines of:

' Play with the 0, 100 numbers here. This is where you'll probably want to take into account the locations of the container holding the chkbox
dim intX as integer = GenerateRandomNumber(0, 100)
dim intY as integer = GenerateRandomNumber(0, 100)
 
' Assuming the name of the checkbox is "chkSike" ...
chkSike.Location = New Point(intX, intY)


Never play leapfrog with a unicorn
STaRDoGG's picture
From:
Olympus
STaRDoGG
Head Mucky MuckJoined the Dark SidePremium Member (Gold)I'm a Code Monkey!The Steel CurtainI use FirefoxI use Google ChromeI use Internet ExplorerI use SafariLinux UserMac UserWindows UserI donated to GeekDrop simply because I love it!Booga Booga BoogaI took a bite of the AppleFormer Phrozen Crew MemberI'm MagicMember of VileThe Dr. put the stem on the apple!The JokerSomeone thinks you're udderly delightful!
Relationship Status:
Divorced
Joined: 01/14/2009
Posts: 2551
Drops: 2998
Mood: Curious
Re: Mouse move event

Btw, you can name variables anything you want; when I first started coding I thought I was being cool by naming my variables things like "iRule", "YerMomIsGhey", "TheShocker", etc., but eventually you'll realize how lame that really is (unless you're trying to mess with crackers Wink ), because it makes going back and understanding your code later a big PITA (pain in the a$$).

the best way to name variables is to start it out with whatever type it is, so you can easily tell just by looking at the variable name what type of data it's holding. i.e. start Integer variables with "int", (intNumber), string variables with "str" (strStuff), boolean variables with "b" or "bool" (bTrueorFalse, boolTrueorFalse), single variables as "sng" (sngNumbers), etc.

It's good to start right off doing it that way to get in the habit and save yourself a lot of headaches down the road.


Never play leapfrog with a unicorn
Evil Monkey's picture
Evil Monkey
Moderator (Watching Over The Masses)Premium Member (Silver)The Steel CurtainI use FirefoxI use Google ChromeI use Internet ExplorerI use SafariI'm Here To Help, & Have Proven It!Windows UserMember of VileThe JokerSomeone thinks you're a Rotten Tomato!STaRDoGG <3's you ;)
Joined: 01/22/2009
Posts: 234
Drops: 350
Re: Mouse move event

OK I'll play around with this. Thanks for the snippet. I hate asking for code and I know it's looked down upon. But when your starting out it can get tough to really come up with it all on your own. I've searched a lot and haven't had any luck coming up with anything close to what I am trying to do. I came up with the mousehover with multiple boxes from a tut on youtube. It didn't really do what I am doing but it got me started. But didn't seem like the best way I could be doing this. Again I undertand the idea behind it, just fall short on the implementation.

One thing I have learned in the few programming classes that I've taken so far is what you said about naming your variables. Make them simple and to the point so you know what your talking about. Remarking your code too helps with going back later to understand what you have written. That I need to get better at. But i'm still just getting started.

--
I hope that after I die, people will say of me: "That guy sure owed me a lot of money.''

Evil Monkey's picture
Evil Monkey
Moderator (Watching Over The Masses)Premium Member (Silver)The Steel CurtainI use FirefoxI use Google ChromeI use Internet ExplorerI use SafariI'm Here To Help, & Have Proven It!Windows UserMember of VileThe JokerSomeone thinks you're a Rotten Tomato!STaRDoGG <3's you ;)
Joined: 01/22/2009
Posts: 234
Drops: 350
Re: Mouse move event

I got that code working in my program last night. I just need to play around with the numbers now. Also want to play with the variable type. One thing I notice that with with the mouse hover event it doesn't seem to react very snappy if you know what I mean. It's like you can catch it pretty easy and get your mouse over it to click it. I'd rather it be really fast as soon as your mouse slightly touches it it moves away. Any idea on how to punch it up? I created a mouse leave event that works the same way as the mouse hover. My thinking is if you did get your mouse over it as soon as you move the mouse again it would move. Not sure though if that helps much or at all.

Also say I want to add function to my quiz that will keep track of your score and display the score on my final form. I'm guessing I'd want to create an array to do this?

I'm still using seperate forms for all my questions. I'd like to change that to use one form but not sure how that would work. I know you mentioned using tabs. I wasn't sure how to do that either. But with tab controls I'd rather not have 10 tabs visible along the top of the quiz really. Can you hide so it doesn't look like it's uisng tabs?

--
I hope that after I die, people will say of me: "That guy sure owed me a lot of money.''

STaRDoGG's picture
From:
Olympus
STaRDoGG
Head Mucky MuckJoined the Dark SidePremium Member (Gold)I'm a Code Monkey!The Steel CurtainI use FirefoxI use Google ChromeI use Internet ExplorerI use SafariLinux UserMac UserWindows UserI donated to GeekDrop simply because I love it!Booga Booga BoogaI took a bite of the AppleFormer Phrozen Crew MemberI'm MagicMember of VileThe Dr. put the stem on the apple!The JokerSomeone thinks you're udderly delightful!
Relationship Status:
Divorced
Joined: 01/14/2009
Posts: 2551
Drops: 2998
Mood: Curious
Re: Mouse move event
Evil Monkey wrote:

I got that code working in my program last night. I just need to play around with the numbers now. Also want to play with the variable type. One thing I notice that with with the mouse hover event it doesn't seem to react very snappy if you know what I mean. It's like you can catch it pretty easy and get your mouse over it to click it. I'd rather it be really fast as soon as your mouse slightly touches it it moves away. Any idea on how to punch it up? I created a mouse leave event that works the same way as the mouse hover. My thinking is if you did get your mouse over it as soon as you move the mouse again it would move. Not sure though if that helps much or at all.

MouseEnter or MouseMove might work then. Sounds like MouseHover waits for the mouse to stop for a second before triggering.

Evil Monkey wrote:

Also say I want to add function to my quiz that will keep track of your score and display the score on my final form. I'm guessing I'd want to create an array to do this?

It depends if it's just a number total, or somethign else. If it's just a number total that your'e adding up, a regular integer variable that you show in a label on the last form is good enough. If you're showing anything else, like different words for each answer, you could use any of the array types. In .net there are arrays, arraylists, collections, hashtables & dictionaries. Arrays are the oldest, collections are nice, but they're trying to phase those out I hear, and hashtables and dictionaries are said to be the most efficient. I tend to just use whichever is easiest at the time though.

Another option (if using a word summary of the score) would be to always keep the last form loaded, but not visible until you want it to be, then add a label or textbox to it, and as they answer things, append the score/answer to the label or textbox. When the form finally shows, it'll have all the stuff right there in the textbox for them to see.

Evil Monkey wrote:

I'm still using seperate forms for all my questions. I'd like to change that to use one form but not sure how that would work. I know you mentioned using tabs. I wasn't sure how to do that either. But with tab controls I'd rather not have 10 tabs visible along the top of the quiz really. Can you hide so it doesn't look like it's uisng tabs?

I haven't looked into the 2010 version of the tabcontrol yet, but in the previous ones, not really. You could just put 10 groupboxes on the form in the same place, put each quiz question in each one separately, then just set each one's visible property to true/false as needed. When you hide a groupbox all of it's contents are hidden with it.


Never play leapfrog with a unicorn
Guest's picture
Guest
Re: Mouse move event

For now I'm just going to leave this as seperate forms. I"ll play with this type of thing again with one form but for now I'm going to leave it as is.

As for the scoring I think I should be able to make a string that get's passed from form to form that will store the data enterend and then that sting can fill in the array. Then on the last form or where ever I have it do the calculation have my "answer key" setup to check against the array. Then display it back to the user as a % correct. I think I can do that. hehehe Will see.

STaRDoGG's picture
From:
Olympus
STaRDoGG
Head Mucky MuckJoined the Dark SidePremium Member (Gold)I'm a Code Monkey!The Steel CurtainI use FirefoxI use Google ChromeI use Internet ExplorerI use SafariLinux UserMac UserWindows UserI donated to GeekDrop simply because I love it!Booga Booga BoogaI took a bite of the AppleFormer Phrozen Crew MemberI'm MagicMember of VileThe Dr. put the stem on the apple!The JokerSomeone thinks you're udderly delightful!
Relationship Status:
Divorced
Joined: 01/14/2009
Posts: 2551
Drops: 2998
Mood: Curious
Re: Mouse move event

That's one way to do it (in coding there's always a hundred different ways to skin a cat), or instead of passing the string to each separate form, you could just add a module to the project, and store the string variable there. Then it's available to use in any form in your project.

Believe it or not, using groupboxes instead of 10 different forms is alot easier (not to mention cleaner).


Never play leapfrog with a unicorn
Guest's picture
Guest
Re: Mouse move event

Yea I'm learning how many options there are to do one thing. Just for learning reasons I'm going to stick with what I have and try to do it with passing the string.

I think then I'm going to make a new quiz with real questions for my students. And I was thinking of trying to use panels instead of sepereate forms. what do you think about using panels?

Who's New

KaylaMorgan's picture
arxeis77's picture
eyoungren's picture
RavingNutter1972's picture
Mridul's picture
Holyryan2346's picture
washim's picture
yeniban's picture
siam3933595's picture
al360's picture
militarymom's picture
Simra's picture
srikanth's picture
joshter1950's picture
bittu's picture
facebook codes exploits tips tricks Phrozen Crew
All contents ©Copyright GeekDrop 2009-2017
TOS | Privacy Policy