From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Measurement Studio for VB6

cancel
Showing results for 
Search instead for 
Did you mean: 

CWGraph Events

I'm having some trouble understanding some of the graph events generated in
VB
I have a typical chart type graph and I want to know whether the user has
clicked
on the area where the plots are drawn or on the area where the axis are
drawn.
I assumed that the MouseUp event would always be generated when the mouse
comes up on the control and PlotAreaMouseUp would only be generated if the
mouse was over the plot area, but this doesn't seem to be the case.
It looks as if both events are generated wherever on the control you click,
also
the Button value in the PlotAreaMouseUp event always seems to be zero,
rather
than the 1,2 or 4 I was expecting.
Any help or advice much appreciated.

Paul Rocca
0 Kudos
Message 1 of 9
(4,414 Views)
Paul,

All of these events are discussed in detail in the ComponentWorks reference for Visual Basic.

You are correct in assuming that the MouseUp event is always generated when a mouse button comes up while over the control. This event returns the parameters button, shift, X and Y. X and Y are the coordinates of the cursor when the mouse button was released.

The PlotMouseUp and PlotAreaMouseUp are both generated at the same time MouseUp is, but they differ in the parameters they return.

PlotMouseUp returns the parameters button, shift, XData, YData, PlotIndex and PointIndex. Here the X and Y values are the actual values of closest point of the selected plot.

PlotAreaMouseUp returns the parameters button, shift, XPos and YPos. The X and Y values here are the act
ual coordinates of the cursor, WITH RESPECT TO THE X & Y AXIS.

For your application, I would recommend using the MouseUp event and comparing the X and Y values to some predefined ranges for the graph and axis. Once you've determined if the mouse button was released inside your "axis" range or "graph" range, you can act accordingly. Good luck!
0 Kudos
Message 2 of 9
(4,414 Views)
Matt R wrote in message
news:50650000000500000093230000-986697009000@quiq.com...
> Paul,
>
> All of these events are discussed in detail in the ComponentWorks
> reference for Visual Basic.

Indeed they are and the help I read on the PlotArea events was

Purpose
PlotAreaMouseDown fires when you click the mouse on the plot area.
PlotAreaMouseMove fires when you move the mouse over the plot area.
PlotAreaMouseUp fires when you release the mouse over the plot area.

I take it then from what you said the help file is incorrect and
PlotAreaMouseUp
fires when the mouse comes up anywhere on the control?

Also the Button parameter is still coming back as zero, no matter which
button I press.

I tried this in a couple of the Measurement Studio examples as w
ell by
putting
Debug.Print Button in the PlotAreaMouseUp event and this also always gives
0 for any single button click. The MouseUp event always gives the expected
value for the Button parameter.

Any Ideas?

Paul
0 Kudos
Message 3 of 9
(4,414 Views)
Paul,

The help file is correct about the PlotAreaMouseUp, I just might not have been clear in my answer.

PlotAreaMouseDown is triggered when the user clicks any mouse button down on the graph. PlotAreaMouseUp is only triggered when the user releases that button.

I created a very simple VB project that just updates a numeric indicator with the button value whenever I trigger a MouseUp event, and it works fine. I'm not sure why the button parameter isn't working for you.
0 Kudos
Message 7 of 9
(4,414 Views)
> The help file is correct about the PlotAreaMouseUp, I just might not
> have been clear in my answer.
>
> PlotAreaMouseDown is triggered when the user clicks any mouse button
> down on the graph. PlotAreaMouseUp is only triggered when the user
> releases that button.
Yes, but PlotAreaMouseUp is being generated whenever the mouse comes
up anywhere over the control, rather than just being generated when the
button
comes up over the plot area of the control.

> I created a very simple VB project that just updates a numeric
> indicator with the button value whenever I trigger a MouseUp event,
> and it works fine. I'm not sure why the button parameter isn't
> working for you.
The MouseUp event does work correctly and gives the correct value
for the Button parameter. It is in the PlotAreaMouseUp that the Button
parameter appears to be incorrect.

Try making a project with a single form, add a graph control
called CWGraph1 and a textbox called Text1.

Set the TrackMode property on the graph to be PlotAreaEvents or
Plot & CursorEvents. (otherwise the PlotAreaMouseUp event is not
generated)

Set the multiline property on the textbox to be true and add a vertical
scrollbar if you want.

Then paste the following bit of code into the code window and then run the
program.

Private Sub CWGraph1_MouseUp(Button As Integer, Shift As Integer, x As
Single, y As Single)
Text1 = Text1 & "In MouseUp Event - Button Parameter = " & Button & vbCrLf
End Sub

Private Sub CWGraph1_PlotAreaMouseUp(Button As Integer, Shift As Integer,
XPos As Variant, YPos As Variant)
Text1 = Text1 & "In PlotAreaMouseUp Event - Button Parameter = " & Button &
vbCrLf
End Sub

The output in the textbox for me for a left, right and then middle click is
as follows.
In PlotAreaMouseUp Event - Button Parameter = 0
In MouseUp Event - Button Parameter = 1
In PlotAreaMouseUp Event - Button Parameter = 0
In MouseUp Event - Button Parameter = 2
In PlotAreaMouseUp Event - Button Parameter = 0
In MouseUp Event - Button Parameter = 4

Also it doesn't seem to matter where on the control I click, both events are
always
generated even when I click on the frame outside of the plot area.
0 Kudos
Message 8 of 9
(4,414 Views)
Matt R wrote in message
news:50650000000500000093230000-986697009000@quiq.com...
> Paul,
>
> All of these events are discussed in detail in the ComponentWorks
> reference for Visual Basic.

Indeed they are and the help I read on the PlotArea events was

Purpose
PlotAreaMouseDown fires when you click the mouse on the plot area.
PlotAreaMouseMove fires when you move the mouse over the plot area.
PlotAreaMouseUp fires when you release the mouse over the plot area.

I take it then from what you said the help file is incorrect and
PlotAreaMouseUp
fires when the mouse comes up anywhere on the control?

Also the Button parameter is still coming back as zero, no matter which
button I press.

I tried this in a couple of the Measurement Studio examples as w
ell by
putting
Debug.Print Button in the PlotAreaMouseUp event and this also always gives
0 for any single button click. The MouseUp event always gives the expected
value for the Button parameter.

Any Ideas?

Paul
0 Kudos
Message 4 of 9
(4,414 Views)
Paul,

You are correct in the fact that the PlotAreaMouseUp and PlotMouseUp do not correctly return the button parameter. This is a known issue that is currently being addressed. However, there is an easy workaround for this issue.

Whenever you click and release on the CWGraph, the MouseUp event is fired. It depends on if you clicked on an actual plot (or just the plot area) which of the PlotMouseUp/PlotAreaMouseUp events will occur. Since the MouseUp event correctly returns the button parameter, you can get the button value from the MouseUp event, and the remainder of the necessary information from the other events. Hope this information helps!
0 Kudos
Message 9 of 9
(4,414 Views)
The Button value in the PlotAreaMouseDown event will always correspond to the mouse button you clicked (1, 2, 4, or some combination if you click more than one button).
0 Kudos
Message 5 of 9
(4,414 Views)
Yes, but what is the Button parameter in PlotAreaMouseUp supposed to be
according to the help files it should be1,2,4 same as the MouseUp event
but it isn't. Is this a bug or am I missing something?

Paul

Aaron wrote in message
news:506500000005000000B3230000-986697009000@quiq.com...
> The Button value in the PlotAreaMouseDown event will always correspond
> to the mouse button you clicked (1, 2, 4, or some combination if you
> click more than one button).
0 Kudos
Message 6 of 9
(4,414 Views)