Re: Floating Box for Prices




"Mike Williams" <mikea@xxxxxxxxxxxxxxxxx> wrote in message
news:%23KlritcZIHA.4196@xxxxxxxxxxxxxxxxxxxxxxx
"Webbiz" <noreply@xxxxxxx> wrote in message
news:uIs2pqVZIHA.1208@xxxxxxxxxxxxxxxxxxxxxxx

I am trying to decide how to activate this floating price box. The
best idea I can come up with is a mousedown delay. If the user
clicks down the left mouse button and holds it for a full 1.5
seconds, then I'd like this box to appear. As long as the button
is held down, it will follow the mouse anywhere on the picturebox.
Once the button is released, the box must go away. What do you
think? It seems like a better idea than having to hold down a key
while moving the mouse. How might I implement this?

As with most things in a user interface, implementing them is usually very
easy. The hard part is deciding exactly what it is you want to implement,
so that it works well and so that the user will find it intuative. Often
with things like floating information windows it is best to use a "hover
period" so that the window appears if the user simply hovers the mouse in
one spot for more than a predetermined period. The operating system uses
this technique a lot, and you'll see something similar if you set the
ToolTip text property of a control on your Form. This "hover" method does
of course require you to set a reasonably large "hover period" though,
otherwise you would have little windows popping up all the time.

However in your specific case your own suggested "hold the mouse down"
technique might be best, considering the details of what it is you want to
do. You don't need to make the user wait as much as your own suggested 1.5
seconds though, even if you are using mouse clicks and double clicks for
other purposes. No matter what the user is doing in the way of standard
clicks and double clicks it is very rare that he will actually hold down
the button for a contiguous period of more than a very small fraction of a
second, unless he is deliberately holding it down for a specific purpose
(to trigger your floating window for example). Making him wait 1.5 seconds
for the window to appear seems a bit long to me. Personally I would
suggest maybe half a second or so.

How might I implement this?

Have a look at the following code. To test it, start a new VB project and
place a PictureBox and a Label and a Timer control on your Form. Then
paste in the following code. This is just "rough and ready" stuff just off
the top of my head, and I am sure that it could be done in a much neater
way if you give it some more thought, but it seems to work very well. The
Label control indicates when the "mouse down for a specified period" has
been activated (by showing itself) and the Label disappears as soon as the
user then lets go of the mouse button (the Label is just an indication of
course, and you would simply modify the code to instead show your little
floating "follow the mouse" information window. Anyway, try clicking and
double clicking lots of times in the PictureBox and you should find that
you can do so fine without the Label ever popping up. But if you hold down
the left mouse button for more than half a second the Label should appear,
and it should go away as soon as you let go of the button. Is this the
sort of effect you are after?

Mike

Option Explicit
Private tDown As Single, counting As Boolean

Private Sub Form_Load()
Timer1.Interval = 100
Timer1.Enabled = True
Label1.Visible = False
End Sub

Private Sub Picture1_MouseDown(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
tDown = Timer
counting = True
End Sub

Private Sub Picture1_MouseUp(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
tDown = 0
counting = False
Label1.Visible = False
End Sub

Private Sub Timer1_Timer()
Dim t1 As Single
If counting Then
t1 = Timer - tDown
If t1 > 0.5 Or t1 < 0 Then
Label1.Visible = True
End If
End If
End Sub



I guess you're right that 1.5 seconds is too long. That came off the top of
my head. I just didn't want it to interfere with my scrolling feature, that
allows scrolling the chart if you double-click and keep the mouse down on
the second click, then move it around to move the chart. (actually, it only
moves the chart once you let go of the mouse button. I'll tackle this issue
another day.)


The above code appears to provide what I'm looking for. Now to study it for
awhile.

Thanks Mike.

Webbiz



.