Image SpecialEffect (1 Viewer)

LEXCERM

Registered User.
Local time
Tomorrow, 05:25
Joined
Apr 12, 2004
Messages
169
Hi all,

I have the following code in the OnLoad event of a form:
Code:
Dim ctrl As Control
For Each ctrl In Me.Form
If ctrl.Tag = "cmdSpecialEffect" Then
ctrl.SpecialEffect = 1
End If
Next ctrl

There are several buttons on this form. I could place a MouseUp/MouseDown event behind each one so that it mimics a command button when pressed. However, is there a more slick way to achieve this on the, say, OnCurrent event a form with just one piece of code?

Many thanks.
 

MarkK

bit cruncher
Local time
Today, 10:25
Joined
Mar 17, 2004
Messages
8,190
What are you trying to do, customize a format for each record as you load it, or handle mouse events? Current event is good for the former, not so much the latter.

The thing I hate about using the Tag property as a means of defining a subset of controls on a form is that it doesn't self document at all, and you have to open a property sheet for each control to determine if it participates in the subset. Maintaining such a structure is a pain.

What I do is explicitly define an array of controls in my code so it's super easy to understand what is going on and it's super easy to update and maintain. Consider this as a custom property of a form...

Code:
private m_ctrlSubset as variant  'will hold an array of controls

property get MyCtrlSubset as variant
  if isempty(m_ctrlSubset) then m_ctrlSubset = Array([B]Me.txt1, Me.txt2, Me.SomeControl[/B])
  MyCtrlSubset = m_ctrlSubset
end property
So now the list of participating controls is super obvious, and super easy to edit, and to poll them all and set a property you can do...
Code:
Dim ctrl As Control
For Each ctrl In Me.MyCtrlSubset
  ctrl.SpecialEffect = 1
Next ctrl
Which'll be faster too, 'cause you're not checking all the controls on the form.

Does that help?
Mark
 

LEXCERM

Registered User.
Local time
Tomorrow, 05:25
Joined
Apr 12, 2004
Messages
169
Hi Mark and thanks for replying.

I'm having an issue with this, but it may be because I haven't placed the code in the right place.

What form event do I place this code in?:
Code:
Dim ctrl As Control
[COLOR="Red"]For Each ctrl In Me.MyCtrlSubset[/COLOR]  
ctrl.SpecialEffect = 1
Next ctrl

I've placed it in the OnCurrent event but it debugs on the red line above.

What I'm trying to achieve is that whenever an image is pressed and released it mimics a command button, rather than having to place MouseUp/MouseDown code behind each button individually.

Many thanks again.
Paul.
 

MarkK

bit cruncher
Local time
Today, 10:25
Joined
Mar 17, 2004
Messages
8,190
If you want to change the appearance of the control in response to a mouse event, you need to handle that mouse event. The current event only occurs when you first load a new record in a form.

If you use the code I posted you have to use both parts. The second depends on the first, but the idea is that you understand what is happening there. If you don't understand it, it is not an advantage for you to use it.

Cheers,
Mark
 

Users who are viewing this thread

Top Bottom