模拟翻转效果 [英] Simulating rollover effects

查看:72
本文介绍了模拟翻转效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我构建了以下代码,模拟了在标签上移动鼠标时常见的

翻转效果(此示例使

标签为粗体。)

我想知道是否有人提出了更好的解决方案。

lq


''开始代码:

Private RolloverBoldFlag As Boolean

函数RolloverBold(myFrm As String,myLabel As Integer)

''更改选定的Z标签字体为粗体OnMouseMove

''和非粗体所有其他Z标签。


''示例:

''用于名为Z1的标签:OnMouseMove = RolloverBold([FormName],1)

''用于名为Z2的标签:OnMouseMove = RolloverBold([FormName],2)

''等

''表单详细信息:OnMouseMove = RolloverBold([FormName],0)

Dim ctl As Control


''确定所选标签:


如果myLabel> 0然后''它是一个标签:


如果表格(myFrm)(Z"& CStr((myLabel)))。FontBold = False那么


''重置所有标签按钮颜色:

For Each ctl In Forms(myFrm).Controls

如果ctl.ControlType = acLabel和_

左(ctl.Name,1)=" Z" _

然后ctl.FontBold = False

下一步ctl


''将所选标签设置为粗体:

表格(myFrm)(" Z"& CStr((myLabel)))。FontBold = True


RolloverBoldFlag = True

结束如果


Else''它不是标签,它是重置所有标签的命令:


如果RolloverBoldFlag = True那么


''重置所有标签按钮颜色:

For Each ctl In Forms(myFrm).Controls

如果ctl.ControlType = acLabel And _

左(ctl.Name,1)=" Z" _

然后ctl.FontBold = False

下一步ctl


RolloverBoldFlag = False


结束如果


结束如果


结束功能


''结束代码

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

我构建了以下代码来模拟常见的
翻转。/>
解决方案

推荐答案

将鼠标移动到标签上时的效果(此示例使标签变为粗体。)

我想知道是否有人提出了更好的解决方案。
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.




我不知道更好。如果你的代码有效,那么它就不会更好了。


我从一本关于VB设计模式的书中删除了这个想法。 />
它工作得相当好但是可以将鼠标移动到

标签上并在退出时保持粗体。


另一种方式是把一个大的标签贴上它的背景颜色

设置为小标签后面的'bg颜色,并使用

标签'的鼠标悬停重置较小标签的事件。


< clsRollOverLabel>

Private WithEvents lbl As Access.Label


Public Sub Init(l As Access.Label)

Set lbl = l

lbl.OnMouseMove =" [Event Procedure]"

结束子


Private Sub lbl_MouseMove(按钮为整数,按整数移位,X为

单,Y为单)

Dim h As Integer

Dim w As Integer


h = lbl.Height

w = lbl.Width


如果X< 32或Y< 32或X> w - 64或Y> h - 64然后

lbl.FontBold = False

否则

lbl.FontBold = True

结束如果< br $>
End Sub

< / clsRollOverLabel>


< form module>

Dim ro As clsRollOverLabel


Private Sub Form_Load()

设置ro =新clsRollOverLabel

ro.Init Me.Label2

结束子


私人子Form_Unload(取消为整数)

设置ro =无任何

结束子
< / form module>



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>


这种方法的问题是如果用户快速滚动鼠标

,不会触发底层标签的OnMouseMove,

标签将保持粗体。我尝试过这种方法,而不是使用OnMouseMov并使用:For Each ctl In,使用表单的详细信息部分来触发undo

bold命令。

表格(myFrm)。控制......

只是我的偏好。


我希望能找到更多优雅想要这样做

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 Quantrell写道:
Lauren Quantrell wrote:
这种方法的问题是,如果用户滚动鼠标<很快,底层标签的OnMouseMove将不会被触发,标签将保持粗体。我尝试过这种方法,而是赞成使用表单的详细信息部分使用OnMouseMov来激活撤销粗体命令的方法,并使用:For Each ctl In
Forms(myFrm) .Controls ...
只是我的偏好。

我希望找到一个更优雅的想做这个
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,


这是你原来的


函数RolloverBold(myFrm As String,myLabel As Integer)


Dim ctl作为控制


如果myLabel> 0然后''它是一个标签:

如果Forms(myFrm)(" Z"& CStr((myLabel)))。FontBold = False那么

For每个ctl In Forms(myFrm).Controls

如果ctl.ControlType = acLabel和Left(ctl.Name,1)=" Z"

那么

ctl.FontBold = False

endif

下一步ctl

表格(myFrm)(" Z"& CStr(( myLabel)))。FontBold = True

RolloverBoldFlag = True

结束如果

否则''它不是标签,它是一个命令重置所有标签:

如果RolloverBoldFlag = True那么

For Ctl In Forms(myFrm).Controls

如果ctl.ControlType = acLabel和左(ctl.Name,1)=" Z"

然后

ctl.FontBold = False

endif

下一步ctl

RolloverBoldFlag = False

结束如果

结束如果


结束功能

我没看到你传递的地方或者使用rolloverbold标志,而且它看起来好像b $ b似乎就像你只能通过标签OnMouseMove调用函数一样,

并且你在两种条件下重置字体,所以你可以将
缩短为(还没有测试过)


Dim ctl作为控制

每个ctl In Forms(myFrm).Controls

如果ctl.ControlType = acLabel和Left(ctl.name,1)=" Z"然后

ctl.FontBold = False

结束如果

下一步ctl


set ctl = Forms (myFrm)(" Z" CStr(myLabel))

如果ctl.FontBold = False那么ctl.FontBold = True

======= =========================================== ======= ===========

一个不太优雅,但可能更快的方式怎么样?


过去,当nbr标签很小,我已经硬编码标签

变更(粗体,或凹陷/凸起)OnMouseMove。


我的套装3个标签,每个都有这样的OnMouseMove代码:

如果Me.lblDocAttach.SpecialEffect = 0那么

Me.lblDocSearch.SpecialEffect = 0

Me.lblDocRetrieve.SpecialEffect = 0

Me.lblDocAttach.SpecialEffect = 1

结束如果


所以每个标签我有5行,一个条件语句得到

评估。当然,维持你拥有的标签越多,或者你申请的设置越多,就越贵。但它的运行速度非常快。


过去我也会在显示时迭代表单控件,但似乎调用函数效率低于
要评估表单上的每个控件,检查

如果它是标签,检查标题或名称,然后做一些事情。我的直觉

感觉硬编码比走控制更快。


也许我错了。如果有人能证明这不是最好的方式(除了
维护噩梦),那就更慢或者使用更多的系统资源,

我会的尝试迭代方法。



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.


这篇关于模拟翻转效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆