Quick Tip: Trapping Mouse Clicks with the User Object

by Jack Wheeler (jwl1@jps.net)

Hey I just figured out how to send email from Alpha Five version 4 (see my first and second articles on email), when I realized I needed a way for users activate my email fields easily and effectively. I was clued in to my deficiencies when a client asked, "How do I send email to the Operations Manager?" That's when I realized that "Duh" was not an acceptable response! Here's what I did:

I decided the most intuitive way for most users to initiate an email transaction is by double-clicking on the email field. Here is the form I use:

tip5a

 As you can see, there are 6 Email fields for different company executives. I wanted the user to be able to click on the Email field of any executive to send an email to that person.

The only Alpha Five objects that respond to mouse double-clicks are browse rows and User Objects. [Editor's note: There's a review of the User Object and associated mouse events in the article on mouse rollovers.]

When I placed the user object over the field, I noticed a problem: the field no longer shows any activation. How on earth was the user going to know where he was? And how would the user ever get to the underlying email field to edit it with the User Object taking up real estate on top of it?

I therefore looked at the listing of events for the user objects, trying to highlight the field when the user object is entered. The natural choice of events was the OnInit event for the User Object. However, I discovered that the User Object's OnInit event only fires when it is entered via the keyboard, not by clicking on it with the mouse! This is harder than I thought!

Okay, Let me rethink this: the only time I need the User Object is when I double click on it. Otherwise any activity in the User Object should activate the underlying email field.

I know that the user will either Tab into the field, Left click into the field or double click into the field. That is all that will happen to this field! The events I will concern myself with are the OnInIt, the OnKey and OnMouse Events. Within the OnMouse event I will use the Left Down and Double Left Click sub-events.

Here are the scripts I ended up with:

OnInit Code: Op is operational manager and the Url is the Email field hence OPURL

dim f as p
f=parentform.this
If f:OPURL.text = "" then
f:OPURL.activate()
f:OPURL.refresh()
end if

OnMouse Event

dim f as p
f=parentform.this
if a_user.mouse.event = "left down" then
 f:OPURL.activate()
 elseif a_user.mouse.event = "left double click" then
 if f:OPURL.text = "" then
 f:OPURL.activate()
 end 
 end if
 file_name="C:\Progra~1\INTERN~1\Iexplore.exe Mailto:"+\
   alltrim(f:OPURL.text)
 sys_shell(file_name,1)
end if

The OnKey event is:

dim f as p
f=parentform.this
f:OPURL.activate()

The OnKey fires if you hit anything on the key board and the user object is active. Combining these methods allows the user to activate the Email field to edit it and to launch an email by double-clicking over the field.

Editor's note: Jack has been very inventive in employing the User Object to make the Email field response to a mouse double-click. However, for those of you who don't want to get involved in User Object programming, I'd like to point out 2 simpler ways to launch an Email from Jack's form. You could place a small button next to each Email field and let the user press the button to launch the email. The code to lauch the email would be contained in the OnPush button event. Alternatively, you could place a HotSpot around the "Email" text before the field, and pressing the HotSpot would also activate the HotSpot's OnPush event. Either one of these methods would be simple to implement but neither one would give Jack the interface he wanted, namely, the ability to launch an email with a mouse double-click.

3/17/00

Don't forget, we need your feedback to make this site better!

Return to home