本文介绍了ZedGraph-如何使水平线可拖动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些水平的直线,希望用户能够垂直拖动.这怎么可能?我认为,用于线选择的最佳参数将是线附近固定数量的像素.因此,如果鼠标为+/- 2像素,则应更改鼠标光标并使线可拖动..我看到CurveItem类具有属性IsSelectable和IsSelected.这些会解决这个问题吗?通过阅读课程文档,我无法真正理解它们的用途.

I have some straight horizontal lines that I want the user be able to drag vertically. How would this be possible? I think the best parameter for line selection would be a fixed number of pixels near the line. So if mouse is +/- 2 pixels, I should change the mouse cursor and make the line drag-able.. I see the CurveItem class has properties IsSelectable and IsSelected. Will these have any function in solving this issue? I can’t really understand what they are for from reading the class documentation..

FindNearestPoint (和 FindNearestObject )似乎仅搜索实际点.如何进行选择以沿直线的整个部分工作?我想我需要做一个自己的自定义查找"例程,该例程遍历我要检查的所有行,并针对每个行基于鼠标X的位置(? )为此,我还在考虑倾斜线,对于水平/垂直线,它会稍微简单一些.至少看来这是curveItem所必需的,但是我认为必须同样地选择LineObj(在其中间)?

It seems that the FindNearestPoint (and FindNearestObject) only search actual points. How would I make selection to work along the whole section of a straight line? I guess I would need to make make my own custom "Find" routine that loops through all the lines I want to check, and for each calculate it's imaginary Y-point based on the mouse X position (?) I'm also thinking about sloped lines for this purpose, for horizontal/vertical lines it will be slightly simpler. At least it seems this is needed for a curveItem, but I assume the same must be done for selecting (at mid-section of) a LineObj?

我实际上不知道 LineObj 的存在.似乎LineObj无法更改 X2/Y2 坐标,因为它们是 ReadOnly .那么,是否有可能拖动LineObj的X2/Y2点?

I actually didn't know about the LineObj existed. It seems the LineObj is not possible to change the X2/Y2 coordinates, as they are ReadOnly. So is it at all possible to drag the X2/Y2 point of a LineObj?

EDIT 2:

在JapaneseCandleStick图上,FindNearestPoint似乎是一个问题;当我在图形窗格中单击时,它不会返回最接近的条形的索引,但是我相信它会选择具有最接近的Y值的索引,无论在x轴上有多远它是.有时是鼠标右侧的条形图,有时是鼠标左侧的条形图.这就是它的工作方式吗?

It seems to be an issue with the FindNearestPoint on a JapaneseCandleStick graph; When I click in the graph pane, it does not return the index of the nearest bar, but I believe it instead selects the index with the closest Y-value, no matter how far away on the x axis it is. Sometimes it's a bar to the right of the mouse, sometimes to the left of the mouse. Is this the way it's meant to work?

我自己制作了此自定义函数,所以我认为还可以..仍然很高兴理解为什么FindNearestPoint以此方式运行.

I made this custom function myself, so I guess it's ok.. Still it would be nice to understand why the FindNearestPoint acts this way.

这是mouseDown上的代码:

This is the code on mouseDown:

   ' Find nearest curve point:
   Dim ciNearestCurve As CurveItem
   Dim iNearestCurve As Integer
   Dim b As Boolean = zgc.GraphPane.FindNearestPoint(mousePt, zgc.GraphPane.CurveList, ciNearestCurve, iNearestCurve)
   If b Then
       With ciNearestCurve(iNearestCurve)
           Debug.Print(Date.FromOADate(.X) & " " & .Y & " " & .Z)
       End With

推荐答案

用鼠标拖动点.

如果使用的是LineObj而不是曲线,请查看 FindNearestObject 方法.

If you are using a LineObj instead of a curve, take a look on the FindNearestObject method.

如果您还想点击一些敏感区域",请此方法应该可以帮助您将以像素为单位的鼠标坐标转换为窗格比例坐标.

Also if you want to make some "area of sensitivity" for clicking, this method should help you to transform mouse coordinates in pixels to pane scale coordinates.

主要思想是:
-订阅MouseDownMouseUpMouseMove事件
-在MouseDown事件的处理程序中,检查单击的点是否在要移动的曲线/图形对象附近
-以类似于第一个链接中示例所示的方式进行更改

The main idea is to:
- subscribe for MouseDown, MouseUp and MouseMove events
- in the handler for MouseDown event check if clicked point is near the curve/graph object you want to move
- do the change in similar way that it is shown in example from the first link

编辑
关于您的
假设您有一条包含两个点的水平曲线myCurve.使用FindNearestPoint,您可以找到最近点击的点包含该点的曲线.

EDIT
Regarding your edit:
Let's assume you have a horizontal curve myCurve containing two points. Using FindNearestPoint you can find nearest clicked point and the curve containing this point.

所以你有

// mousePt is where you clicked
CurveItem nearestCurve = null;
int nearestID = -1;

myPane.FindNearestPoint(mousePt, out nearestCurve, out nearestID);
if(nearestCurve!=null)
   // remember the curve somewhere.

下一步处理MouseMoveMouseUp事件,以找出移动曲线所需的量.您只需知道Y(或Y2)方向的变化,因为曲线是水平的,并且您可能不想沿X轴移动.

Next handle the MouseMove and MouseUp events to find out how much you need to move your curve. You need to know only the change in Y (or Y2) direction as the curve is horizontal and you probably do not want to move it along X axis.

当您发现需要移动曲线(dy)多少时,只需执行以下操作:

When you'll find out how much you need to move your curve (dy), just do:

for(int i=0; i<nearestCurve.Points.Count; i++)
    nearestCurve.Points[i].Y += dy;

关于第二个问题,在 LineObj.Location.Y2 的文档中, :

Regarding your second question, in the documentation for LineObj.Location.Y2 you have:

Width/Height属性可以轻松设置,因此您可以通过这种方式进行设置.

And Width/Height properties can be set easily, so you can do it this way.

这篇关于ZedGraph-如何使水平线可拖动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 18:54