Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 538
Default Determine closest control to MouseUp event?

Is there an easy, accurate method to determine the closest control to a
MouseUp (or MouseDown, if it's easier) event, if the user clicks on the
UserForm instead of a control? (My form will be used on a touch screen.)

My current best guess is to do it manually (so to speak): look at the
coordinates of the click, and then look at the coordinates of each control
and decide which one is closest. I'm sure it'll work, but it's going to be a
PITA, and I'm looking for something built-in, or alternately code that's
already been written. (My google-fu has failed me here.)

--
Nobody gives a damn about me, or anybody else.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,182
Default Determine closest control to MouseUp event?

Is there an easy, accurate method to determine the closest control to
a MouseUp (or MouseDown, if it's easier) event, if the user clicks
on the UserForm instead of a control? (My form will be used on a
touch screen.)

My current best guess is to do it manually (so to speak): look at the
coordinates of the click, and then look at the coordinates of each
control and decide which one is closest. I'm sure it'll work, but
it's going to be a PITA, and I'm looking for something built-in, or
alternately code that's already been written. (My google-fu has
failed me here.)


Mouse clicks will be measured/scaled in screen position. Controls on a
userform are positioned from 0,0 (top,left) of the form. You'll need to
do some conversion and control mapping to do this. Wouldn't it be
easier/better, though, for the user to just click the desired control?
Or use the Tab key to move around the controls in the order you've
defined?

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default Determine closest control to MouseUp event?


"Auric__" wrote in message
Is there an easy, accurate method to determine the closest control to a
MouseUp (or MouseDown, if it's easier) event, if the user clicks on the
UserForm instead of a control? (My form will be used on a touch screen.)

My current best guess is to do it manually (so to speak): look at the
coordinates of the click, and then look at the coordinates of each control
and decide which one is closest. I'm sure it'll work, but it's going to be
a
PITA, and I'm looking for something built-in, or alternately code that's
already been written. (My google-fu has failed me here.)


If I follow your objective try this

Private Sub UserForm_Initialize()
Dim r As Single, c As Single
Dim ctl As MSForms.Control
Const pad As Single = 18
Const ht As Single = 18
Const wd As Single = 90

For c = 0 To 2
For r = 0 To 5
Set ctl = Me.Controls.Add("Forms.CommandButton.1")
With ctl
.Left = 9 + c * (pad + wd)
.Top = 9 + r * (pad + ht)
.Width = wd
.Height = ht
.Caption = .Name
End With
Next
Next

End Sub


Private Sub UserForm_MouseUp(ByVal Button As Integer, _
ByVal Shift As Integer, _
ByVal X As Single, ByVal Y As Single)
Dim ctl As MSForms.Control
Dim idx As Long, idxMin As Long
Dim z As Single, zMin As Single

zMin = 1234567
idxMin = -1

For Each ctl In Me.Controls
With ctl
If .Left <= X And .Left + .Width = X Then
If .Top Y Then
z = .Top - Y
Else
z = Y - .Top - .Height
End If
ElseIf .Top <= Y And .Top + .Height = Y Then
If .Left X Then
z = .Left - X
Else
z = X - .Left - .Width
End If
ElseIf .Left X Then
If .Top Y Then
z = ((.Left - X) ^ 2 + (.Top - Y) ^ 2) ^ 0.5
Else
z = ((.Left - X) ^ 2 + (Y - .Top - .Height) ^ 2) ^ 0.5
End If
Else
If .Top Y Then
z = ((X - .Left - .Width) ^ 2 + (.Top - Y) ^ 2) ^ 0.5
Else
z = ((X - .Left - .Width) ^ 2 + (Y - .Top - .Height) ^ 2) ^ 0.5
End If
End If
End With

If z < zMin Then
zMin = z: idxMin = idx
End If
idx = idx + 1
Next

If idxMin = 0 Then
Me.Controls(idxMin).SetFocus
End If

End Sub

** only lightly tested! **

Regards,
Peter T


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 93
Default Determine closest control to MouseUp event?

Auric__ wrote:
Is there an easy, accurate method to determine the closest control to a
MouseUp (or MouseDown, if it's easier) event, if the user clicks on the
UserForm instead of a control? (My form will be used on a touch screen.)

My current best guess is to do it manually (so to speak): look at the
coordinates of the click, and then look at the coordinates of each control
and decide which one is closest. I'm sure it'll work, but it's going to be a
PITA, and I'm looking for something built-in, or alternately code that's
already been written. (My google-fu has failed me here.)

Javascript can definitely get you X,Y pixel positions. Screen is
ASS-u-MEd to be 80x600, fixed.

Snippet from working code at http://www.oil4lessllc.org/gTX.htm:
<head
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
<titleTexas Stripper Wells and Production</title
<style type="text/css"
</style
</head

<body
<SCRIPT type="text/javascript"
var yr= 0; var awls = new Array(); var aprd = new Array(); var yar =
new Array();

awls[1941]="31,126"; awls[1942]="30,763"; awls[1943]="-";
awls[1944]="32,170"; awls[1945]="35,000";
awls[1946]="33,678"; awls[1947]="32,528"; awls[1948]="38,053";
awls[1949]="39,759"; awls[1950]="46,197";
awls[1951]="42,956";
///more array stuff///
aprd[1998]="128,822,329"; aprd[1999]="131,129,272";
aprd[2000]="135,151,385"; aprd[2001]="129,017,097";
aprd[2002]="127,252,695";
aprd[2003]="128,058,395"; aprd[2004]="126,260,710";
aprd[2005]="139,959,142"; aprd[2006]="147,506,457*";
aprd[2007]="119,683,522";
aprd[2008]="-";
var lin=""; var leg=" ";

legend="*Estimated #Not available -No data !Revised ?Suspect
&Confirmed"

var isNav = (navigator.appName.indexOf("Netscape") !=-1);
function handlerMM(e){
Xmm = (isNav) ? e.pageX : event.clientX;
Ymm = (isNav) ? e.pageY : event.clientY;
yr=Math.round((Xmm-116)/7.414286+1940);
lin=""; leg="";
if (yr1940) {
if (yr<=2008) {
yar[yr]=yr;
lin=yr+" Production of "+aprd[yr]+" BBLs from "+awls[yr]+" wells";
if ( lin.indexOf("*") -1 ) {
leg="*Estimated ";
}
if ( lin.indexOf("#") -1 ) {
lin=yr+" Information not available";
}
if ( lin.indexOf("-") -1 ) {
lin=yr+" No data";
}
if ( lin.indexOf("!") -1 ) {
leg=leg+"!Revised ";
}
if ( lin.indexOf("?") -1 ) {
leg=leg+"?Suspect ";
}
if ( lin.indexOf("&") -1 ) {
leg=leg+"&Confirmed ";
}
}

else {
lin=""; leg="";
}
}
document.dataholder.datlin.value=lin;
document.dataholder.com.value=leg;
}
if (isNav) {
document.captureEvents(Event.MOUSEMOVE);
}
document.onmousemove = handlerMM;
</SCRIPT

<!-- style and then img src as separate items makes IE happy; GIF
is 90% BMP --

<div style="position: absolute; height: 341px; width: 720px; top: 80px;
left: 0px; "
<img src="Texas.gif" alt="" usemap="#TX" style="border-style:none"
</div

<!-- cannot use "len" to specify size below --
<div style="position: absolute; top: 1px; left: 120px; "
<form name="dataholder" action=""
<table border=0
<tr
<td<input type="text" size=57 name="datlin" value="0"</td
<td<input type="text" size=25 name="com" value="0"</td
</tr
</table
</form
</div

<div style="position: absolute; height: 312px; width: 518px; top: 420px;
left: 120px; "
<img src="TXdaily.jpg" alt="daily" style="border-style:none"
</div

<div style="position: absolute; top: 30px; left: 300px; " <H3<i© 2013
Oil 4 Less LLC</i</H3</div

</body
</html

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 538
Default Determine closest control to MouseUp event?

GS wrote:

Is there an easy, accurate method to determine the closest control to
a MouseUp (or MouseDown, if it's easier) event, if the user clicks
on the UserForm instead of a control? (My form will be used on a
touch screen.)

My current best guess is to do it manually (so to speak): look at the
coordinates of the click, and then look at the coordinates of each
control and decide which one is closest. I'm sure it'll work, but
it's going to be a PITA, and I'm looking for something built-in, or
alternately code that's already been written. (My google-fu has
failed me here.)


Mouse clicks will be measured/scaled in screen position. Controls on a
userform are positioned from 0,0 (top,left) of the form. You'll need to
do some conversion and control mapping to do this. Wouldn't it be
easier/better, though, for the user to just click the desired control?


Yes, of course, but...

Or use the Tab key to move around the controls in the order you've
defined?


Not necessarily. Let me clarify a bit.

This form has 33 textboxes, 2 comboboxes, a listbox, and a button. All of
them are tabstops. (There are also labels and another button that aren't tab
stops, but they don't matter.) The user doesn't have to hit tab 35 times to
go from the first box to the last, of course, but being designed for
touchscreens, I expect that users will run into fat finger syndrome pretty
often, hitting the form background rather than the control they wanted.

I want to try to work around that a bit by guessing which control the user
wants. The best method I've thought of is what I described above. (Hitting a
label will move the focus to the associated text/combo/listbox.)

(I can't adjust the size and/or layout of the boxes very much because I'm
assuming the on-screen keyboard will be used for data entry. On my tiny
tablet, there is literally not enough screen space for anything except the
form and the OSK.)

--
On the Internet all men are men,
all women are men,
and all children are FBI agents.


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 538
Default Determine closest control to MouseUp event?

Peter T wrote:

"Auric__" wrote in message
Is there an easy, accurate method to determine the closest control to a
MouseUp (or MouseDown, if it's easier) event, if the user clicks on the
UserForm instead of a control? (My form will be used on a touch screen.)

My current best guess is to do it manually (so to speak): look at the
coordinates of the click, and then look at the coordinates of each
control and decide which one is closest. I'm sure it'll work, but it's
going to be a PITA, and I'm looking for something built-in, or
alternately code that's already been written. (My google-fu has failed me
here.)


If I follow your objective try this


[snip code]

** only lightly tested! **


Looks promising. I'll hack away at it tonight and see what happens. Thank
you.

--
heh, i dont even know how to hack a system
i am always amazed when i hear such stories
hell, half the time I can't get into my own damn box, much less someone elses
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 538
Default Determine closest control to MouseUp event?

Robert Baer wrote:

Auric__ wrote:
Is there an easy, accurate method to determine the closest control to a
MouseUp (or MouseDown, if it's easier) event, if the user clicks on the
UserForm instead of a control? (My form will be used on a touch
screen.)

My current best guess is to do it manually (so to speak): look at the
coordinates of the click, and then look at the coordinates of each
control and decide which one is closest. I'm sure it'll work, but it's
going to be a PITA, and I'm looking for something built-in, or
alternately code that's already been written. (My google-fu has failed
me here.)

Javascript can definitely get you X,Y pixel positions. Screen is ASS-u-MEd
to be 80x600, fixed.


[snip code]

....okay. Now just show me how that will work with Excel.

--
He was here just a minute ago...
-- George Carlin's desired epitaph
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,182
Default Determine closest control to MouseUp event?

GS wrote:

Is there an easy, accurate method to determine the closest control
to a MouseUp (or MouseDown, if it's easier) event, if the user
clicks on the UserForm instead of a control? (My form will be used
on a touch screen.)

My current best guess is to do it manually (so to speak): look at
the coordinates of the click, and then look at the coordinates of
each control and decide which one is closest. I'm sure it'll work,
but it's going to be a PITA, and I'm looking for something
built-in, or alternately code that's already been written. (My
google-fu has failed me here.)


Mouse clicks will be measured/scaled in screen position. Controls on
a userform are positioned from 0,0 (top,left) of the form. You'll
need to do some conversion and control mapping to do this. Wouldn't
it be easier/better, though, for the user to just click the desired
control?


Yes, of course, but...

Or use the Tab key to move around the controls in the order you've
defined?


Not necessarily. Let me clarify a bit.

This form has 33 textboxes, 2 comboboxes, a listbox, and a button.
All of them are tabstops. (There are also labels and another button
that aren't tab stops, but they don't matter.) The user doesn't have
to hit tab 35 times to go from the first box to the last, of course,
but being designed for touchscreens, I expect that users will run
into fat finger syndrome pretty often, hitting the form background
rather than the control they wanted.

I want to try to work around that a bit by guessing which control the
user wants. The best method I've thought of is what I described
above. (Hitting a label will move the focus to the associated
text/combo/listbox.)

(I can't adjust the size and/or layout of the boxes very much because
I'm assuming the on-screen keyboard will be used for data entry. On
my tiny tablet, there is literally not enough screen space for
anything except the form and the OSK.)


How about shifting focus in the label_Click event?

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default Determine closest control to MouseUp event?


"Auric__" wrote in message
Peter T wrote:

"Auric__" wrote in message
Is there an easy, accurate method to determine the closest control to a
MouseUp (or MouseDown, if it's easier) event, if the user clicks on the
UserForm instead of a control? (My form will be used on a touch screen.)

My current best guess is to do it manually (so to speak): look at the
coordinates of the click, and then look at the coordinates of each
control and decide which one is closest. I'm sure it'll work, but it's
going to be a PITA, and I'm looking for something built-in, or
alternately code that's already been written. (My google-fu has failed
me
here.)


If I follow your objective try this


[snip code]

** only lightly tested! **


Looks promising. I'll hack away at it tonight and see what happens. Thank
you.


Seeing what you've added adjacent about what controls you want and don't
want activated, in the loop

For Each ctl In Me.Controls
Select Case TypeName(ctl)
Case "CommandButton", "ComboBox", "TextBox", "ListBox"
' get the 'z' distance from the ctl to the XY etc as per the example

As you've got labels which'll only respond to their own events, better to
make the example a separate routine that receives X & Y, ie can be called by
mouseup over any control (such as Labels) and the form. With controls
calculate and pass the relative XY from the top left of the form. All quite
simple thouh if you've got lots of labels use WithEvents in a separate class
module.

Peter T


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Chart MouseUp Event Feedback Amit Velingkar [MSFT] Charts and Charting in Excel 2 October 26th 09 03:06 AM
How to determine the closest value? Eric Excel Discussion (Misc queries) 7 November 11th 08 02:24 AM
MouseUp Event Does Not Fire TC[_10_] Excel Programming 2 April 6th 08 02:36 AM
MouseUP event avi Excel Programming 1 October 5th 07 11:44 PM
MouseUp Event Paddler Excel Programming 2 October 5th 06 09:16 AM


All times are GMT +1. The time now is 11:48 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"