2012-09-05 60 views
0

滾動Zedgraph的圖形外軸刻度是否有可能在圖形外軸刻度可以使用鼠標事件是規模「MOUSE_DOWN並持有」,並或在y軸相同的上下移動x軸向左或向右移動?恩。當我觸發MouseDownEvent並保持x軸的比例爲0.6或與該比例一起的空間並將其向右移動時,比例應該滾動取決於圖表分數?你能舉個例子嗎?提前致謝!如何使用鼠標事件

回答

0

如果我正確理解你的問題,這是我的迴應:

zedgraph得到了所謂的「泛」的內置功能,你可以改變X & Y軸的規模。

將光標置於「圖表區」內 按住「Ctrl」鍵&移動鼠標朝X & y方向改變比例。

,你可以通過「取消潘」(上下文菜單)

乾杯.. :)回到原來的狀態

+0

San,我明白你在說什麼,但我真正想要的是在圖表區域之外使該功能「不在圖表區域」。例如。我有x軸比例0.0 0.1 0.2 0.3。我想單擊並按住刻度標籤0.1,然後向左移動鼠標,同時它應該重新縮放到0.1 0.2 0.3 0.4。 – Cold

0

你想創建一個滾動條?

zedGraphControl1.IsShowHScrollbar = true; 
//Set borders for the scale 
zedGraphControl1.GraphPane.XAxis.Scale.Max = Xmax; 
zedGraphControl1.GraphPane.XAxis.Scale.Min = Xmin; 
1

分別平移和縮放ÿ軸系可以使用ZedGraph的鼠標事件來實現:MouseDownEventMouseMoveEventMouseUpEventMouseWheel事件(學分去我的同事)。

它與多個GraphPanes和多ÿ軸系。

MouseMoveEvent用於當在按下其按鈕以移動鼠標來移動最小值和Y軸的最大如果不是,則用於獲取鼠標懸停在其上的Y軸對象的引用。

MouseDownEvent用於啓動軸線平移操作。

MouseWheel用於上的Y軸執行縮放。

而且MouseUpEvent使用縮放和平移操作時完成清理的東西。

下面是代碼:

// The axis that is currently hovered by the mouse 
YAxis hoveredYAxis; 

// The graphpane that contains the axis 
GraphPane foundPane; 

// The scale of the axis before it is panned 
double movedYAxisMin; 
double movedYAxisMax; 

// The Y on the axis when the panning operation is starting 
float movedYAxisStartY; 

void z_MouseWheel(object sender, MouseEventArgs e) 
{ 
    if (hoveredYAxis != null) 
    { 
     var direction = e.Delta < 1 ? -.05f : .05f; 
     var increment = direction * (hoveredYAxis.Scale.Max - hoveredYAxis.Scale.Min); 
     var newMin = hoveredYAxis.Scale.Min + increment; 
     var newMax = hoveredYAxis.Scale.Max - increment; 

     hoveredYAxis.Scale.Min = newMin; 
     hoveredYAxis.Scale.Max = newMax; 

     foundPane.AxisChange(); 

     z.Invalidate(); 
    } 
} 

bool z_MouseUpEvent(ZedGraphControl sender, MouseEventArgs e) 
{ 
    hoveredYAxis = null; 
    return false; 
} 

bool z_MouseMoveEvent(ZedGraphControl sender, MouseEventArgs e) 
{ 
    var pt = e.Location; 

    if (e.Button == System.Windows.Forms.MouseButtons.Left) 
    { 
     if (hoveredYAxis != null) 
     { 
      var yOffset = hoveredYAxis.Scale.ReverseTransform(pt.Y) - hoveredYAxis.Scale.ReverseTransform(movedYAxisStartY); 
      hoveredYAxis.Scale.Min = movedYAxisMin - yOffset; 
      hoveredYAxis.Scale.Max = movedYAxisMax - yOffset; 

      sender.Invalidate(); 
      return true; 
     } 
    } 
    else 
    { 
     var foundObject = findZedGraphObject(null); 
     hoveredYAxis = foundObject as YAxis; 

     if (hoveredYAxis != null) 
     { 
      z.Cursor = Cursors.SizeNS; 
      return true; 
     } 
     else 
     { 
      if (z.IsShowPointValues) 
      { 
       z.Cursor = Cursors.Cross; 
       return false; 
      } 
      else 
      { 
       z.Cursor = Cursors.Default; 
       return true; 
      } 
     } 
    } 

    return false; 
} 

bool z_MouseDownEvent(ZedGraphControl sender, MouseEventArgs e) 
{ 
    if (e.Button == System.Windows.Forms.MouseButtons.Left) 
    { 
     if (hoveredYAxis != null) 
     { 
      movedYAxisStartY = e.Location.Y; 
      movedYAxisMin = hoveredYAxis.Scale.Min; 
      movedYAxisMax = hoveredYAxis.Scale.Max; 
      return true; 
     } 
    } 

    return false; 
} 

這是一個因子分解有點對象找到ZedGraph的操作的幫手。

object findZedGraphObject(GraphPane pane = null) 
{ 
    var pt = zgc.PointToClient(Control.MousePosition); 

    if (pane == null) 
    { 
     foundPane = zgc.MasterPane.FindPane(pt); 
     if (foundPane != null) 
     { 
      object foundObject; 
      int forget; 

      using (var g = zgc.CreateGraphics()) 
       if (foundPane.FindNearestObject(pt, g, out foundObject, out forget)) 
        return foundObject; 
     } 
    } 

    return null; 
} 
+0

Gist可用:https://gist.github.com/grumly57/7524673 – Larry

+0

我用這個,稍作修改,通過滑動y軸本身來縮放y軸。謝謝! – Luminous

+0

哦,我的,這是舊東西。我會盡快發佈更新。格拉斯它幫助! – Larry