11-17-2014 11:55 AM
Hello,
Currently I am using a graph control(ni waveformgraph) in a vb app (vs2010) . Scrolling, which works well by my point of view, is deemed too complicated by the client. They want (of course) something "different". The native way to scroll the graph is to hold down the CTRL key and "grab" the wavefrom and move it.
Is there a way to implement say horizontal scrolling by pressing a button for left and a buttonn for right scrolling? A button press would scrool it one tic(basic X axis resolution). I have thought about using sendkeys but I thoght I should aks if someone might already have a solution.
Thanks,
bartj
11-18-2014 05:23 PM
I haven't seen an implementation like this before. Have you tried using send keys like you mentioned?
11-18-2014 09:22 PM
All,
I was able to make this work in the following manner:
Public Declare Sub keybd_event Lib "user32" Alias "keybd_event" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Int32, ByVal dwExtraInfo As Int32)
Const VK_LEFT = &H25
Const VK_UP = &H26
Const VK_RIGHT = &H27
Const VK_DOWN = &H28
Const VK_CONTROL = &H11
Public Const KEYEVENTF_KEYUP = &H2
Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
' test to scroll the graph without the mouse or multi keys...
' must set the focu to the graph
WaveformGraph1.Focus()
keybd_event(VK_CONTROL, 0, 0, 0) ' press ctrl
keybd_event(VK_LEFT, 0, 0, 0) ' press left arrow
keybd_event(VK_LEFT, 0, KEYEVENTF_KEYUP, 0) ' releaseleft arrow
keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0) ' release ctrl
End Sub
11-19-2014 02:15 AM
Hello,
I would say that your approach is unnecessary complicated. You should obtain your X/Y axis from your graph property, and simply change it's range.
So if you like to scroll your graph on Yaxis by let's say 1 unit down you should do this (sorry for C#):
void button_Click(...) { var currentRange = yourGraphName.YAxes[indexOfAxe].Range; yourGraphName.YAxes[indexOfAxe].Range = new Range(currentRange.Minimum - 1, currentRange.Maximum - 1); }
I wrote this code from top of my head and without trying it, because I don't have access to computer with MS installed at this moment, so there might be some errors. However this code has much better approach to your problem in my opinion.
Best regards,
Filip S.
11-19-2014 10:42 AM
Filip,
Your solution works great! I just needed to change the axis from y to x for my needs. Great simple solution.
Thanks!
bartj
11-20-2014 01:53 AM
I'm happy to hear that. You are welcome.
Filip S.