473,383 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Simulating rollover effects

I have constructed the following code that simulates the common
rollover effect when moving the mouse over a label (this example makes
the label bold.)
I'm wondering if anyone has come up with a better solution.
lq

'start code:
Private RolloverBoldFlag As Boolean
Function RolloverBold(myFrm As String, myLabel As Integer)
' Change the selected "Z" label font to bold OnMouseMove
' and un-bolds all other "Z" labels.

' Examples:
' for a label named "Z1" : OnMouseMove = RolloverBold([FormName],1)
' for a label named "Z2" : OnMouseMove = RolloverBold([FormName],2)
' etc.
' for the form detail: OnMouseMove = RolloverBold([FormName],0)
Dim ctl As Control

'determine the selected label:

If myLabel > 0 Then 'it is a label:

If Forms(myFrm)("Z" & CStr((myLabel))).FontBold = False Then

'reset all label buttons colors:
For Each ctl In Forms(myFrm).Controls
If ctl.ControlType = acLabel And _
Left(ctl.Name, 1) = "Z" _
Then ctl.FontBold = False
Next ctl

'set selected label to bold:
Forms(myFrm)("Z" & CStr((myLabel))).FontBold = True

RolloverBoldFlag = True
End If

Else 'it is not a label, it is a command to reset all labels:

If RolloverBoldFlag = True Then

'reset all label buttons colors:
For Each ctl In Forms(myFrm).Controls
If ctl.ControlType = acLabel And _
Left(ctl.Name, 1) = "Z" _
Then ctl.FontBold = False
Next ctl

RolloverBoldFlag = False

End If

End If

End Function

'end code

Nov 13 '05 #1
47 7541
rkc
Lauren Quantrell wrote:
I have constructed the following code that simulates the common
rollover effect when moving the mouse over a label (this example makes
the label bold.)
I'm wondering if anyone has come up with a better solution.


I don't know about better. If your code works then it can't get
better.

I ripped this idea off from a book I have on VB design patterns.
It works fairly well but it is possible to race the mouse over
the label and leave it bold on exit.

Another way is to put a large label with it's background color
set to the form's bg color behind the smaller label and use
that label's mouseover event to reset the smaller label.

<clsRollOverLabel>
Private WithEvents lbl As Access.Label

Public Sub Init(l As Access.Label)
Set lbl = l
lbl.OnMouseMove = "[Event Procedure]"
End Sub

Private Sub lbl_MouseMove(Button As Integer, Shift As Integer, X As
Single, Y As Single)
Dim h As Integer
Dim w As Integer

h = lbl.Height
w = lbl.Width

If X < 32 Or Y < 32 Or X > w - 64 Or Y > h - 64 Then
lbl.FontBold = False
Else
lbl.FontBold = True
End If
End Sub
</clsRollOverLabel>

<form module>
Dim ro As clsRollOverLabel

Private Sub Form_Load()
Set ro = New clsRollOverLabel
ro.Init Me.Label2
End Sub

Private Sub Form_Unload(Cancel As Integer)
Set ro = Nothing
End Sub
</form module>
Nov 13 '05 #2
The problem with that approach is that if the user rolls the mouse very
quickly, the OnMouseMove of the underlying label will not be fired and
the label will remain bold. I have tried this approach and instead
favor the approach of using the form's detail section to fire the undo
bold command using OnMouseMov and using: For Each ctl In
Forms(myFrm).Controls...
Just my preference.

I'm hoping to find a more elegant want to do this

Nov 13 '05 #3
DFS
Lauren Quantrell wrote:
The problem with that approach is that if the user rolls the mouse
very quickly, the OnMouseMove of the underlying label will not be
fired and the label will remain bold. I have tried this approach and
instead favor the approach of using the form's detail section to fire
the undo bold command using OnMouseMov and using: For Each ctl In
Forms(myFrm).Controls...
Just my preference.

I'm hoping to find a more elegant want to do this


Lauren,

Here's your original

Function RolloverBold(myFrm As String, myLabel As Integer)

Dim ctl As Control

If myLabel > 0 Then 'it is a label:
If Forms(myFrm)("Z" & CStr((myLabel))).FontBold = False Then
For Each ctl In Forms(myFrm).Controls
If ctl.ControlType = acLabel And Left(ctl.Name, 1) = "Z"
then
ctl.FontBold = False
endif
Next ctl
Forms(myFrm)("Z" & CStr((myLabel))).FontBold = True
RolloverBoldFlag = True
End If
Else 'it is not a label, it is a command to reset all labels:
If RolloverBoldFlag = True Then
For Each ctl In Forms(myFrm).Controls
If ctl.ControlType = acLabel And Left(ctl.Name, 1) = "Z"
then
ctl.FontBold = False
endif
Next ctl
RolloverBoldFlag = False
End If
End If

End Function
I don't see where you're passing or using the rolloverbold flag, and it
seems like you would only call the function from a label OnMouseMove anyway,
and you're resetting the font in both conditions, so you may be able to
shorten to (haven't tested it)

Dim ctl As Control
For Each ctl In Forms(myFrm).Controls
If ctl.ControlType = acLabel And Left(ctl.name, 1) = "Z" Then
ctl.FontBold = False
End If
Next ctl

set ctl = Forms(myFrm)("Z" & CStr(myLabel))
If ctl.FontBold = False Then ctl.FontBold = True
================================================== ==================
How about a less elegant, but potentially faster, way?

In the past, when the nbr of labels is small, I've hard coded the labels
that get changed (bold, or sunken/raised) OnMouseMove.

For my set of 3 labels, each gets OnMouseMove code like this:

If Me.lblDocAttach.SpecialEffect = 0 Then
Me.lblDocSearch.SpecialEffect = 0
Me.lblDocRetrieve.SpecialEffect = 0
Me.lblDocAttach.SpecialEffect = 1
End If

So for each label I have 5 lines, and one condition statement that gets
evaluated. It's a bear to maintain the more labels you have, of course, or
the more settings you apply. But it runs blazingly fast.

In the past I've also iterated the form controls as you show, but it seems
inefficient to call a function to evaluate every control on the form, check
if it's a label, check the caption or the name, then do something. My gut
feeling is the hard-coding is quicker than walking the controls.

Maybe I'm wrong. If someone can prove it's not the best way (excepting
maintenance nightmares), that it's slower or uses more system resources,
I'll try the iterative method.
Nov 13 '05 #4

Lauren Quantrell wrote:
I'm wondering if anyone has come up with a better solution.


This is a different solution. It's quite old (1999). I've quickly
modified it to bring it in line with AC2000, so it may be buggy.

http://ffdba.com/downloads/Hover Demo 2000.dat

rename to "Hover Demo 2000.mdb"

Nov 13 '05 #5
rkc
Lauren Quantrell wrote:
The problem with that approach is that if the user rolls the mouse very
quickly, the OnMouseMove of the underlying label will not be fired and
the label will remain bold. I have tried this approach and instead
favor the approach of using the form's detail section to fire the undo
bold command using OnMouseMov and using: For Each ctl In
Forms(myFrm).Controls...
Just my preference.

I'm hoping to find a more elegant want to do this


Well, I guess you can't beat Lyle Fairfield's offering for elegant.

The solution to the background label approach is to use just one
label for the background and make it cover the entire area. The
drawback is that you have to use the class approach as in my first
example.

I have to tell you though, the one time I implemented this in a
real project the client emailed me an hour latter and asked me
to "stop making it do that."



Nov 13 '05 #6
http://ffdba.com/downloads/Hover.dat
(rename to "Hover.mdb")

is a classless rendition created in Access 2003 but I think there is
nothing in it that would require anything more than Access 97.

Nov 13 '05 #7
rkc
Lauren Quantrell wrote:
The problem with that approach is that if the user rolls the mouse very
quickly, the OnMouseMove of the underlying label will not be fired and
the label will remain bold. I have tried this approach and instead
favor the approach of using the form's detail section to fire the undo
bold command using OnMouseMov and using: For Each ctl In
Forms(myFrm).Controls...
Just my preference.

I'm hoping to find a more elegant want to do this


O.K. After a cup of coffee and a couple of chocolate pop tarts
I figured out how to watch the form's detail section for a
mouseover event. This seems to solve the rapid mouse move problem.
<clsRollOverLabel>
Private WithEvents mLabel As Label
Private WithEvents mBackGround As Access.Section

Public Function SetTextLabel(lbl As Label)

Set mLabel = lbl
mLabel.OnMouseMove = "[Event Procedure]"
Set mBackGround = mLabel.parent.Detail
mBackGround.OnMouseMove = "[Event Procedure]"

End Function

Private Sub mBackGround_MouseMove(Button As Integer, Shift As Integer, X
As Single, Y As Single)
mLabel.FontBold = False
End Sub

Private Sub mlabel_MouseMove(Button As Integer, Shift As Integer, X As
Single, Y As Single)
mLabel.FontBold = True
End Sub
</clsRollOverLabel>

Nov 13 '05 #8
Does this work when there is no visible detail section?

Nov 13 '05 #9
rkc
lylefair wrote:
Does this work when there is no visible detail section?


Good question. Probably not. But, then the op was using the
Detail mouseover to trigger their function so I figured...

You will have to explain to me a situation where there would be
no visible Detail section, but the Detail section would still
contain controls.

Can you make your solution work without a Timer event?
Nov 13 '05 #10
Not right now .... :-)

Nov 13 '05 #11
rkc
lylefair wrote:
Not right now .... :-)


I have faith.

Nov 13 '05 #12
Thanks for the reply.
The problem with this:

Dim ctl As Control
For Each ctl In Forms(myFrm).Controls
If ctl.ControlType = acLabel And Left(ctl.name, 1) = "Z" Then
ctl.FontBold = False
End If
Next ctl
set ctl = Forms(myFrm)("Z" & CStr(myLabel))
If ctl.FontBold = False Then ctl.FontBold = True

....is that it fires as long as the mouse is over the control and things
flash on the screen. The boolean RooloverBoldFlag stops code exexution
when False
Yes, I hard code when there are only a few controls.

Nov 13 '05 #13
I think you have it here!

Nov 13 '05 #14
rkc <rk*@rochester.yabba.dabba.do.rr.bomb> wrote in
news:E1*******************@twister.nyroc.rr.com:
I ripped this idea off from a book I have on VB design patterns.
It works fairly well but it is possible to race the mouse over
the label and leave it bold on exit.

Another way is to put a large label with it's background color
set to the form's bg color behind the smaller label and use
that label's mouseover event to reset the smaller label.


No, all you have to do is use the mouseover event of the form detail
to turn off the effects. You then need to have some way of knowing
which ones to turn off, or you have to turn off the rollover for all
controls to which it applied.

Back in Access 2 days, I used someone's example for simulating
tooltips that worked on this principle, but since it opened a form,
it was a lot easier to remove the effect, as there was only one
object that need to be acted upon.

I don't find rollovers to be terribly useful. They basically say
"Look! Your mouse is over me!!!!!!" Since that information is
already avaiable to you, it's only useful if the boundaries are not
clear in the first place, which would seem to me to be a design
error in the first place.

Now, I *can* see using the OnEnter event of controls to make their
labels bold or something like that. What I don't think is useful is
doing that when a the mouse is over a control.

The exception to that would be when you're doing it with labels to
replicate command bottons. This example:

http://www.dfenton.com/DFA/Splash/JKA.jpg

uses mouseover of the labels and invisible command buttons on top of
the labels, with the mouseover event of the form detail set to set
all the labels to transparent borders. That's no big deal when
there's only a small number of labels, as in this case.

But I've never done rollovers *except* for a small number of items,
so have never bothered to code anything more sophisticated.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #15
"DFS" <nospam@dfs_.com> wrote in news:8g*****************@fe04.lga:
How about a less elegant, but potentially faster, way?

In the past, when the nbr of labels is small, I've hard coded the
labels that get changed (bold, or sunken/raised) OnMouseMove.


That's exactly the kind of situation that benefits greatly from
using a custom collection, with only the controls in it that you
want acted upon. You are right -- walking the entire controls
collection *is* slow, but having to hardcode control names is a
pain.

The method I use is to use the Tag property to define which
collection a control belongs to, then populate the the collection(2)
in the form's OnLoad event by walking Controls collection and
checking the Tag property.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #16
After I think about this some more I plan to stick with the timer
event. (Barring further insight).
The mousemove event occurs (I believe) multiple times as the cursor
moves across a control. We need to know only when it enters the area
and when it leaves. I expect that we could API these particular events
with a callback, but it has always been my position that one should use
VBA when one can, and the API when one can't; here, with the timer one
can, and one needs to do so only with a frequency that will delude our
eyes and mind into thinking the whole thing is continuous. Thus, in
this particular case, I expect that the timer may be more effiecint
than mousemove. It's also AC97 doable, while callbacks with 97 require
quite a bit of hopp jumping.
Also I'm returning to using a class. I used classes extensively years
ago when they were not so well known, or popular. But I've largely
stopped. They may be slower than standard modules. But there is at
least one place where they are efficient. That is where we have some
code that uses modularly scoped or static variables that store the
property values of an object. In this case the class stores the
locations of the form's labels. Each time the hover procedure runs,
these locations do not have to be reesetablished. With a standard
module and modularly scoped or static variables, one can store values
for only one form. With a class, one has one instance of the class for
each form and as a result a distinct set of properties that identify
the lovation of each of the form's controls. As I have implied, this is
one of the few uses, or the only use, I make of class modules.
Tonight or tomorrow, I'll try to make available a new verion of
hover.mdb that incorporates both these strategies.

Nov 13 '05 #17
rkc
David W. Fenton wrote:

Replies inline.
rkc <rk*@rochester.yabba.dabba.do.rr.bomb> wrote in
news:E1*******************@twister.nyroc.rr.com:

I ripped this idea off from a book I have on VB design patterns.
It works fairly well but it is possible to race the mouse over
the label and leave it bold on exit.

Another way is to put a large label with it's background color
set to the form's bg color behind the smaller label and use
that label's mouseover event to reset the smaller label.

No, all you have to do is use the mouseover event of the form detail
to turn off the effects. You then need to have some way of knowing
which ones to turn off, or you have to turn off the rollover for all
controls to which it applied.


Yes. Ended up doing just that.
Back in Access 2 days, I used someone's example for simulating
tooltips that worked on this principle, but since it opened a form,
it was a lot easier to remove the effect, as there was only one
object that need to be acted upon.

I don't find rollovers to be terribly useful. They basically say
"Look! Your mouse is over me!!!!!!" Since that information is
already avaiable to you, it's only useful if the boundaries are not
clear in the first place, which would seem to me to be a design
error in the first place.
They're only useful if someone asks for them.
Now, I *can* see using the OnEnter event of controls to make their
labels bold or something like that. What I don't think is useful is
doing that when a the mouse is over a control.

The exception to that would be when you're doing it with labels to
replicate command bottons. This example:

http://www.dfenton.com/DFA/Splash/JKA.jpg
This is exactly what I was doing when the client asked me to knock it
off. They hadn't asked for it. Lesson learned.
uses mouseover of the labels and invisible command buttons on top of
the labels, with the mouseover event of the form detail set to set
all the labels to transparent borders. That's no big deal when
there's only a small number of labels, as in this case.

But I've never done rollovers *except* for a small number of items,
so have never bothered to code anything more sophisticated.


Well it seems there really is nothing to be more sophisticated about.
Unless you are still using A97. A simple label rollover ended up taking
six lines of code not counting the declarations. Of course initializing
everything in the form module takes more code. That would most easily
be done using a collection as you have pointed out on numerous occasions.


Nov 13 '05 #18
And after looking at <http://ffdba.com/downloads/Hover Demo 2000.dat> a
bit more I doubt there are any significant changes I would make to the
code at this time unless someone can point out a biggie.

Nov 13 '05 #19
>>The mousemove event occurs (I believe) multiple times as the cursor
moves across a control. <<

Which is why I use Private RolloverBoldFlag As Boolean in my original
question's code. It stops the code there is the OnMouseMove is over the
same object.

I avoid timers in general.

Nov 13 '05 #20

Lauren Quantrell wrote:
The mousemove event occurs (I believe) multiple times as the cursor

moves across a control. <<

Which is why I use Private RolloverBoldFlag As Boolean in my original
question's code. It stops the code there is the OnMouseMove is over the
same object.

I avoid timers in general.


Events <=> Timer

Nov 13 '05 #21
Agreed, unless Screen.ActiveControl.Name lurks...

Nov 13 '05 #22
>I don't find rollovers to be terribly useful. They basically say
"Look! Your mouse is over me!!!!!!" Since that information is
already avaiable to you, it's only useful if the boundaries are not
clear in the first place, which would seem to me to be a design
error in the first place.


I think most people now accustomed to the web see this as "Look! Your
mouse is over me - and becaue I'm highlighted, clicking me will do
something..."
lq

Nov 13 '05 #23
"Lauren Quantrell" <la*************@hotmail.com> wrote in
news:11**********************@f14g2000cwb.googlegr oups.com:
I don't find rollovers to be terribly useful. They basically say
"Look! Your mouse is over me!!!!!!" Since that information is
already avaiable to you, it's only useful if the boundaries are
not clear in the first place, which would seem to me to be a
design error in the first place.


I think most people now accustomed to the web see this as "Look!
Your mouse is over me - and becaue I'm highlighted, clicking me
will do something..."


But a command button is BY DEFINITION something you click on in
order to do something.

I think the main reason for rollovers in web pages was because
graphic designers hated the look of underlining as an indication of
a clickable link. Because of that, they got rid of the underline,
and then they needed some way to indicate that the text was a link.

In other words, they made the problem for themselves.

I think Microsoft's flat toolbars are exactly the same. Toolbars are
collections of buttons. Buttons are clickable. But when you get rid
of the 3D bevel, it's no longer obvious that it's a button, nor what
the boundaries of the clickable area are. Thus, you need the
mouseover event to make the button 3D to show the boundaries.

From where I sit, this is all a case of letting appearance override
long-term UI conventions, and the result is that you create problems
that have to be solved some other way. But the problem was created
by avoiding the customary way of doing things, so I have no sympathy
for those who feel forced to jump through hoops with rollovers.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #24
I keep working with this from time to time.
My latest (2005-10-18 17:50) is
http://ffdba.com/downloads/Hover.dat
(change name to
Hover.mdb).
No. I'm not totally happy with it but there may be a few ideas there
that will interest the curious.

Nov 13 '05 #25
Lauren Quantrell wrote:
Agreed, unless Screen.ActiveControl.Name lurks...


I've done mouse hovers by subclassing the control, i.e. defining it via a Class (e.g.
"clsControl") that allows the user to define controls but then let's the class sink events
via the WithEvents keyword. Something like:

Private WithEvents mLabel As Access.Label
.....
Public Property Set addLabel(newctl As Access.Label)

Set mLabel = newctl

mLabel.OnMouseMove = "[Event procedure]"
mLabel.OnClick = "[Event procedure]"

End Property

The problem with this approach can be the overwhelming number of events that come from
moving the mouse within the defined region. I used a flag variable the first time the
mouse moves into a region (via callback to the form) that runs the appropriate code once
and then sets the flag off.

I've used it in a table display with projects as the row and mileposts as the columns.
Hovering over a cell gives more detail than the cell could hold. Double-clicking drills
down to the detail level.
--
'---------------
'John Mishefske
'---------------
Nov 13 '05 #26
"The problem with this approach can be the overwhelming number of
events that come from
moving the mouse within the defined region. I used a flag variable the
first time the
mouse moves into a region (via callback to the form) that runs the
appropriate code once
and then sets the flag off. "

John, yes, this Flag approach is the method I have adopted, but without
the Class.
But I have modified it like this:

Public myP as integer
' myP is a flag holder for the last highlighted label
Sub RolloverUnderline(myFrm as string, myX as integer)
' myX is the current label under the mouse cursor
' all eligible labels are named PmyX EXAMPLE: P1, P2, P3 etc.

Select Case myX
Case 0 '>reset label
If myP > 0 Then 'unset previous label:
If myP <> myX Then _
Forms(myfrm)("P" & CStr((myP))).FontUnderline =
False
myP = 0
End If
Case Else 'highlight label
If myP <> myX Then
'>unset previous label:
If myP > 0 Then _
Forms(myfrm)("P" & CStr((myP))).FontUnderline =
False
'set the current label:
Forms(myfrm)("P" & CStr((myX))).FontUnderline = True
'designate the current label
myP = myX
End If
End Select

End Sub

Nov 13 '05 #27
Lauren Quantrell wrote:
"The problem with this approach can be the overwhelming number of
events that come from
moving the mouse within the defined region. I used a flag variable the
first time the
mouse moves into a region (via callback to the form) that runs the
appropriate code once
and then sets the flag off. "

John, yes, this Flag approach is the method I have adopted, but without
the Class.
But I have modified it like this:

Public myP as integer
' myP is a flag holder for the last highlighted label
Sub RolloverUnderline(myFrm as string, myX as integer)
' myX is the current label under the mouse cursor
' all eligible labels are named PmyX EXAMPLE: P1, P2, P3 etc.

Select Case myX
Case 0 '>reset label
If myP > 0 Then 'unset previous label:
If myP <> myX Then _
Forms(myfrm)("P" & CStr((myP))).FontUnderline =
False
myP = 0
End If
Case Else 'highlight label
If myP <> myX Then
'>unset previous label:
If myP > 0 Then _
Forms(myfrm)("P" & CStr((myP))).FontUnderline =
False
'set the current label:
Forms(myfrm)("P" & CStr((myX))).FontUnderline = True
'designate the current label
myP = myX
End If
End Select

End Sub


Yes, once I did that the form became very responsive and eliminated problems with (as I
recall) recursive calls (events) or stack problems or some such. Thanks for the example.

--
'---------------
'John Mishefske
'---------------
Nov 13 '05 #28
It works quite well and without the screen flicker I've seen with other
examples (since it can only execute once for the same label or
background label-cleaner)

Similar functions for FontBold or ForeColor instead of FontUnderline
work the same way on the same or different forms. What I do is name
labels that may be underlined P1, P2 etc; labels that may be bold X1,
X2 and labels that may be colorized U1, U2.

lq

Nov 13 '05 #29
rkc
Lauren Quantrell wrote:
It works quite well and without the screen flicker I've seen with other
examples (since it can only execute once for the same label or
background label-cleaner)


I'm curious as to how many controls on a single form you are adding
rollovers to. I take it your using them for more than just a menu type
thing.
Nov 13 '05 #30
I'm using them alaso for labels that look act like hyperlinks.

Nov 13 '05 #31
rkc
Lauren Quantrell wrote:
I'm using them alaso for labels that look act like hyperlinks.


Before this thread I hadn't noticed that labels that come automagically
attached to controls have no events. I guess I didn't have any reason
to know up until now.

Nov 13 '05 #32
rkc <rk*@rochester.yabba.dabba.do.rr.bomb> wrote in
news:FX*******************@twister.nyroc.rr.com:
Lauren Quantrell wrote:
I'm using them alaso for labels that look act like hyperlinks.


Before this thread I hadn't noticed that labels that come
automagically attached to controls have no events. I guess I
didn't have any reason to know up until now.


I can't figure out what utility there is to having a rollover on a
label precisely because the label has no events -- it can't do
anything so what is useful in telegraphing to the user the fact that
their mouse pointer is over the label?

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #33

David W. Fenton wrote:

.....
I can't figure out what utility there is to having a rollover on a
label precisely because the label has no events -- it can't do
anything ....


I didn't know that.

Nov 13 '05 #34
rkc
David W. Fenton wrote:
rkc <rk*@rochester.yabba.dabba.do.rr.bomb> wrote in
news:FX*******************@twister.nyroc.rr.com:

Lauren Quantrell wrote:
I'm using them alaso for labels that look act like hyperlinks.


Before this thread I hadn't noticed that labels that come
automagically attached to controls have no events. I guess I
didn't have any reason to know up until now.

I can't figure out what utility there is to having a rollover on a
label precisely because the label has no events -- it can't do
anything so what is useful in telegraphing to the user the fact that
their mouse pointer is over the label?


Stand alone labels have mouse and click events.

I don't think I ever said there was a use to any of it.
Nov 13 '05 #35
rkc
Lauren Quantrell wrote:
"The problem with this approach can be the overwhelming number of
events that come from
moving the mouse within the defined region. I used a flag variable the
first time the
mouse moves into a region (via callback to the form) that runs the
appropriate code once
and then sets the flag off. "

John, yes, this Flag approach is the method I have adopted, but without
the Class.


I'm probably boring the crap out of you by now, but with the class
method all you have to do is check if the property is what it's supposed
to be before changing it.
Nov 13 '05 #36
rkc wrote:
David W. Fenton wrote:
rkc <rk*@rochester.yabba.dabba.do.rr.bomb> wrote in
news:FX*******************@twister.nyroc.rr.com:
Lauren Quantrell wrote:

I'm using them alaso for labels that look act like hyperlinks.
Before this thread I hadn't noticed that labels that come
automagically attached to controls have no events. I guess I
didn't have any reason to know up until now.


I can't figure out what utility there is to having a rollover on a
label precisely because the label has no events -- it can't do
anything so what is useful in telegraphing to the user the fact that
their mouse pointer is over the label?

Stand alone labels have mouse and click events.

I don't think I ever said there was a use to any of it.


Not sure if there is a bit of sarcasm here; my clients love the rollover labels because of
the ability to determine status (via color), the ability to see expanded info (by
hovering) and see all the details by clicking on the "label". For me its a slam-dunk
development tool. My 15 x 10 cell table is updated by writing code in one place - the
sub-classed event. And because it uses Classes it been a time-saver to implement in other
projects.

It may not adhere to the MS or IBM GUI standardization but its a crowd-pleaser and
money-maker.

--
'---------------
'John Mishefske
'---------------
Nov 13 '05 #37
I solved the problem of having multiple rollover effects: underline,
bold, color changes, by using a multidimension array to hold the status
of each form and to prevent the OnMouseMove from triggering more than
once for any form (once that is to set the rollover effect and once to
restore it to normal state.)
It all seems very efficient and is accomplished with minimal code.

Anyone interested and I'll post the code.

lq

Nov 13 '05 #38
"Lauren Quantrell" <la*************@hotmail.com> wrote in
news:11*********************@g44g2000cwa.googlegro ups.com:
I solved the problem of having multiple rollover effects: underline,
bold, color changes, by using a multidimension array to hold the status
of each form and to prevent the OnMouseMove from triggering more than
once for any form (once that is to set the rollover effect and once to
restore it to normal state.)
It all seems very efficient and is accomplished with minimal code.

Anyone interested and I'll post the code.


Please do! I've used some code from long ago by Dev Ashish and David Fenton
to make rollover effects. I'd really like to see how you do it.

TIA
Johan

Nov 13 '05 #39
Johan <no*****@nospam.com> wrote in
news:Xn**********************@130.133.1.4:
"Lauren Quantrell" <la*************@hotmail.com> wrote in
news:11*********************@g44g2000cwa.googlegro ups.com:
I solved the problem of having multiple rollover effects:
underline, bold, color changes, by using a multidimension array
to hold the status of each form and to prevent the OnMouseMove
from triggering more than once for any form (once that is to set
the rollover effect and once to restore it to normal state.)
It all seems very efficient and is accomplished with minimal
code.

Anyone interested and I'll post the code.


Please do! I've used some code from long ago by Dev Ashish and
David Fenton to make rollover effects. I'd really like to see how
you do it.


I doubt rollover code came from me, unless it's *very* primitive in
comparsion to what Lauren and Lyle were doing.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #40
This example is a bit code intensive to show the logic behind having
multiple rollover effects available in your Access application.

What this accomplishes is that the code is executed only once for any
of the rollover effects you want on your forms without having it
execute constantly during the OnMouseMove event, eliminating flashing
and other undesirable effects.

With the example below you can have labels that get underlined, labels
that get bolded and labels that get colorized on the same form or
independently on any form.

What is required here is that you have a naming convention for your
labels:
Labels that will be underlined are all named Q1, Q2, Q3 etc.
Labels that will be bolded are all named Z1, Z2, Z3 etc.
Labels that will be colorized are all named X1, X2, X3 etc.

You must also give each form that will have rollover effects a unique
form index value in Function myFrmIndex. (NOTE: Using the "Private
Const myFrmIndexValue As Integer = 1" on each form (shown in code
below) is repetitive but eliminates the form calling the function
myFrmIndex every time the mouse moves.)

lq
Create a module named modRolloverEffects

Paste the following code into modRolloverEffects:

Option Compare Database
Option Explicit

'multidimensional array to hold record status of every form's rollover
effect status _
- first value hold form's index value, second value hold true/false
for each of the three rollover effects

Public flagRolloverStatus(1 To 100, 1 To 3) As Boolean
'x values (1 to 100) where 100 is the total number of forms you are
using in myFrmIndex below: _
integer values returned by function myFrmIndex
'y values: _
flagRolloverStatus(,1) = "Q(x) Underline labels _
flagRolloverStatus(,2) = "Z(x)" Bold labels _
flagRolloverStatus(,3) = "X(x)" Color labels

Private Function myFrmIndex(myFrm As String) As Integer
'PURPOSE: Extract the form index based on the form name _
NOTE: MAKE SURE THIS IS IN SYNC WITH: Private Const myFrmValue _
USED IN ALL form MODULES

Select Case myFrm

Case "frmNameOne": myFrmIndex = 1
Case "frmNameTwo": myFrmIndex = 2
Case "frmNameThree": myFrmIndex = 3
'etc. for each form having rollover effects

End Select

End Function

Sub TESTflagRolloverStatus()
'PURPOSE: Test/Display the values in multidimensional array:
flagRolloverStatus

Dim x As Integer, Y As Integer
For x = 1 To 100
For Y = 1 To 3
Debug.Print flagRolloverStatus(x, Y)
Next Y
Next x

End Sub
Function LabelUnderlined(myFrm As String, myLabel As Integer)
'PURPOSE: Underline the "Q(x)" field labels

Dim i As Integer, x As Integer, myIndex As Integer

'get the frmIndex of the current form:
myIndex = myFrmIndex(myFrm)

'un-set the total numer of "Q" labels on the form
Select Case myFrm

Case "frmNameOne"
x = 11 'there are 11 "Q" labels on this form
For i = 1 To x
Forms(myFrm)("Q" & CStr((i))).FontUnderline = False
Next i

Case "frmNameTwo" 'demonstrates a subform:
x = 10 'there are 10 "Q" labels on this subform
For i = 1 To x
Forms!frmNameTwo.ChildName.Form("Q" &
CStr((i))).FontUnderline = False
Next i

Case "frmNameThree"
x = 12 'there are 12 "Q" labels on this form
For i = 1 To x
Forms(myFrm)("Q" & CStr((i))).FontUnderline = False
Next i

'etc. Case else

End Select

If myLabel > 0 Then
Select Case myFrm
Case "frmNameTwo" 'subform:
Forms!frmNameTwo.ChildName.Form("Q" &
CStr((myLabel))).FontUnderline = True
Case Else 'main form:
Forms(myFrm)("Q" & CStr((myLabel))).FontUnderline = True
End Select
'>mark the flag:
flagRolloverStatus(myIndex, 1) = True
Else
'>mark the flag:
flagRolloverStatus(myIndex, 1) = False
End If

End if

End Function

Function LabelBold(myFrm As String, myLabel As Integer)
'PURPOSE: Bold the "Z(x)" field labels

Dim i As Integer, x As Integer, myIndex As Integer

'get the frmIndex of the current form:
myIndex = myFrmIndex(myFrm)

'un-set the total numer of "Z" labels on the form
Select Case myFrm

Case "frmNameOne"
x = 5 'there are 5 "Z" labels on this form
For i = 1 To x
Forms(myFrm)("Z" & CStr((i))).FontBold = False
Next i

Case "frmNameTwo" 'demonstrates a subform:
x = 3 'there are 3 "Z" labels on this subform
For i = 1 To x
Forms!frmNameTwo.ChildName.Form("Z" &
CStr((i))).FontBold = False
Next i

Case "frmNameThree"
x = 20 'there are 20 "Z" labels on this form
For i = 1 To x
Forms(myFrm)("Z" & CStr((i))).FontBold = False
Next i

'etc. Case else

End Select

If myLabel > 0 Then
Select Case myFrm
Case "frmNameTwo" 'subform:
Forms!frmNameTwo.ChildName.Form("Z" &
CStr((myLabel))).FontBold = True
Case Else 'main form:
Forms(myFrm)("Z" & CStr((myLabel))).FontBold = True
End Select
'>mark the flag:
flagRolloverStatus(myIndex, 2) = True
Else
'>mark the flag:
flagRolloverStatus(myIndex, 2) = False
End If

End if

End Function

Function LabelColored(myFrm As String, myLabel As Integer)
'PURPOSE: Color the "X(x)" field labels red

Dim i As Integer, x As Integer, myIndex As Integer

'get the frmIndex of the current form:
myIndex = myFrmIndex(myFrm)

'un-set the total numer of "X" labels on the form
Select Case myFrm

Case "frmNameOne"
x = 50 'there are 50 "X" labels on this form
For i = 1 To x
Forms(myFrm)("X" & CStr((i))).ForeColor = 0
Next i

Case "frmNameTwo" 'demonstrates a subform:
x = 3 'there are 3 "X" labels on this subform
For i = 1 To x
Forms!frmNameTwo.ChildName.Form("X" &
CStr((i))).ForeColor = 0
Next i

Case "frmNameThree"
x = 25 'there are 25 "X" labels on this form
For i = 1 To x
Forms(myFrm)("X" & CStr((i))).FontColor = 0
Next i

'etc. Case else

End Select

If myLabel > 0 Then
Select Case myFrm
Case "frmNameTwo" 'subform:
Forms!frmNameTwo.ChildName.Form("X" &
CStr((myLabel))).ForeColor = 0
Case Else 'main form:
Forms(myFrm)("X" & CStr((myLabel))).ForeColor = 255 'red
End Select
'>mark the flag:
flagRolloverStatus(myIndex, 3) = True
Else
'>mark the flag:
flagRolloverStatus(myIndex, 3) = False
End If

End if

End Function

In the code module for frmNameOne paste the following:

Private Const myFrmIndexValue As Integer = 1

Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, x As
Single, Y As Single)

'>reset the underlined labels:
If flagRolloverStatus(myFrmIndexValue, 1) = True Then Call
LabelUnderlined(Me.FormName,0)

'>reset the bold labels:
If flagRolloverStatus(myFrmIndexValue, 2) = True Then Call
LabelBold(Me.FormName,0)

'>reset the colored labels:
If flagRolloverStatus(myFrmIndexValue, 3) = True Then Call
LabelColored(Me.FormName,0)

End Sub
In the code module for frmNameTwo paste the following:

Private Const myFrmIndexValue As Integer = 2
In the code module for frmNameThree paste the following:

Private Const myFrmIndexValue As Integer = 3

Labels:

In the Property Sheet of a label named Q1 you want underlined paste the
following in the OnMouseMove event:
=LabelUnderlined([FormName],1)

In the Property Sheet of a label named Q2 you want underlined paste the
following in the OnMouseMove event:
=LabelUnderlined([FormName],2)

'etc.

In the Property Sheet of a label named Z1 you want bold paste the
following in the OnMouseMove event:
=LabelBold([FormName],1)

In the Property Sheet of a label named Z2 you want bold paste the
following in the OnMouseMove event:
=LabelBold([FormName],2)

'etc.

In the Property Sheet of a label named X1 you want colored red paste
the following in the OnMouseMove event:
=LabelColored([FormName],1)

In the Property Sheet of a label named X2 you want colored red paste
the following in the OnMouseMove event:
=LabelColored([FormName],2)

'etc.

Nov 13 '05 #41
"Lauren Quantrell" <la*************@hotmail.com> wrote in
news:11**********************@z14g2000cwz.googlegr oups.com:

Thanks, Lauren!
The array solution is interesting.
Just a thought: there must be a way to avoid hard-coding form names and
form indexes, as well as the number of controls that have the effect in
question. Also, I'd prefer an approacj that doesn't take that I keep track
of a series of numbers in the controls' names.
Maybe you could write a function that loops through the control collection
of the form (in the form's On Open event), counts those with the effect in
question, creates the array and throws their control names into it, instead
of an index number? The label's On Mouse Move event could pass its name
instead of a number.
You could also use the tag property of the controls to mark it for a
certain effect, instead of the control name. This could be an advantage for
several reasons: you might want to follow a naming convention that tells
you more about the control than Z3. Or, if you change your mind about the
effect for a certain control, you won't have to rename it and then update
the name on every other occurence in your code of that particular control.

Caveat: I'm a bit rusty, so I might have got it all wrong... :-)

--
Johan

Nov 13 '05 #42
"David W. Fenton" <dX********@bway.net.invalid> wrote in
news:Xn**********************************@216.196. 97.142:
Johan <no*****@nospam.com> wrote in
news:Xn**********************@130.133.1.4:
"Lauren Quantrell" <la*************@hotmail.com> wrote in
news:11*********************@g44g2000cwa.googlegro ups.com:
I solved the problem of having multiple rollover effects:
underline, bold, color changes, by using a multidimension array
to hold the status of each form and to prevent the OnMouseMove
from triggering more than once for any form (once that is to set
the rollover effect and once to restore it to normal state.)
It all seems very efficient and is accomplished with minimal
code.

Anyone interested and I'll post the code.


Please do! I've used some code from long ago by Dev Ashish and
David Fenton to make rollover effects. I'd really like to see how
you do it.


I doubt rollover code came from me, unless it's *very* primitive in
comparsion to what Lauren and Lyle were doing.


Correct, the rollover part came from Dev Ashish and only for one kind of
rollover effect at a time.

I used your code to (among other things) create and populate the
collection of controls that would be highlighted on rollover. Unlike
Lauren, I used the controls' tag property, not the naming convention, to
mark the controls.

--
Johan

Nov 13 '05 #43
Johan <no*****@nospam.com> wrote in
news:Xn**********************@130.133.1.4:
"David W. Fenton" <dX********@bway.net.invalid> wrote in
news:Xn**********************************@216.196. 97.142:
Johan <no*****@nospam.com> wrote in
news:Xn**********************@130.133.1.4:
"Lauren Quantrell" <la*************@hotmail.com> wrote in
news:11*********************@g44g2000cwa.googlegro ups.com:

I solved the problem of having multiple rollover effects:
underline, bold, color changes, by using a multidimension array
to hold the status of each form and to prevent the OnMouseMove
from triggering more than once for any form (once that is to
set the rollover effect and once to restore it to normal
state.) It all seems very efficient and is accomplished with
minimal code.

Anyone interested and I'll post the code.

Please do! I've used some code from long ago by Dev Ashish and
David Fenton to make rollover effects. I'd really like to see
how you do it.


I doubt rollover code came from me, unless it's *very* primitive
in comparsion to what Lauren and Lyle were doing.


Correct, the rollover part came from Dev Ashish and only for one
kind of rollover effect at a time.

I used your code to (among other things) create and populate the
collection of controls that would be highlighted on rollover.
Unlike Lauren, I used the controls' tag property, not the naming
convention, to mark the controls.


That occurred to me as a possibility after I'd clicked SEND, since
I'm such an advocate of using custom collections.

The disadvantage to the tag-based approach is that tags can have
only one value, and unless you start storing lists of values (and
parsing that with InStr()), you can't have a control that is in two
different custom collections. I ran onto this recently when I
stepped on a previously defined collection by overwriting the tag
properties of a number of controls that were already participating
in a different collection. I ended up giving the subset of controls
that were in both collections a 3rd tag, and tested for both tags in
the definition of the two collections.

Messy, but it worked, and an inherent flaw of tags used in this
fashion.

I'm not sure what the solution to this problem would be, except
storing the data in a table dedicated to that purpose, but that
means the documentation is outside the form itself, and and much
harder to maintain. The great thing about tags is that is'so easy to
add a control to the custom collection.

I know that the Access Developers Handbook has code for handling
multiple values in tags, but I always thought it was something of a
kludge.

Too bad we can't create custom properties of controls.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #44
"David W. Fenton" <dX********@bway.net.invalid> wrote in
news:Xn**********************************@216.196. 97.142:
Johan <no*****@nospam.com> wrote in
news:Xn**********************@130.133.1.4:
"David W. Fenton" <dX********@bway.net.invalid> wrote in
news:Xn**********************************@216.196. 97.142:
[snip]
I doubt rollover code came from me, unless it's *very* primitive
in comparsion to what Lauren and Lyle were doing.


Correct, the rollover part came from Dev Ashish and only for one
kind of rollover effect at a time.

I used your code to (among other things) create and populate the
collection of controls that would be highlighted on rollover.
Unlike Lauren, I used the controls' tag property, not the naming
convention, to mark the controls.


That occurred to me as a possibility after I'd clicked SEND, since
I'm such an advocate of using custom collections.

The disadvantage to the tag-based approach is that tags can have
only one value, and unless you start storing lists of values (and
parsing that with InStr()), you can't have a control that is in two
different custom collections.


[snip]

I've used tags for storing two or three different values, the way you
suggest here. {IIRC the code I used to split the tag originated in
another piece of code or idea posted by you... :-) }
It worked of course, but I agree with your "kludge"-assessment. It wasn't
very elegant and led to code that wasn't as clear and obvious as one
could wish.

--
Johan

Nov 13 '05 #45
Earlier in this thread I posted code that does that - looping through
controls ( ... if Left(ctl.name,1) = "Z" then... next ctl.)
I prefaced the code I posted saying it was code intensive to show the
logic behing using a multidimensional array to handle multiple rollover
effects on the same forms. I wrote it this way just so people could
follow the logic. In real use I do in fact loop through controls and
don't have to count the controls. I agree with Don in not using the tag
property for the reason's he states and prefer using the
multidimensional array to keep track of the form status rather than
each control's status. That's a matter of choice - which is harder?
Renaming all the labels Z1, Z2 etc or keeping track of which labels
have referenced tag properties. I find it's easier when going through a
list of controls on a form to recognize that all labels named Q(x)
offer underlining rollover effects, Z(x) offer bold effects, etc.
That's just a matter of choice.
Anyone looking at that code can see a way to cut it down to a few lines
very easily, but I posted it as such to expose the logic.
lq

Nov 13 '05 #46
"Lauren Quantrell" <la*************@hotmail.com> wrote in
news:11**********************@g49g2000cwa.googlegr oups.com:

[snip]
Anyone looking at that code can see a way to cut it down to a few lines
very easily, but I posted it as such to expose the logic.


Well, maybe not anyone. Worked for me, though. ;-)
Thanks again!

--
Johan

Nov 13 '05 #47
Point taken.

Nov 13 '05 #48

This thread has been closed and replies have been disabled. Please start a new discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.