2013-02-03 55 views

回答

1

試試這個:

private Point mousePoint; 

    private void chart1_MouseMove(object sender, MouseEventArgs e) 
    { 
     if (e.Button == System.Windows.Forms.MouseButtons.Left) 
     { 
      if (mousePoint.IsEmpty) 
       mousePoint = e.Location; 
      else 
      { 

       int newy = chart1.ChartAreas[0].Area3DStyle.Rotation + (e.Location.X - mousePoint.X); 
       if (newy < -180) 
        newy = -180; 
       if (newy > 180) 
        newy = 180; 

       chart1.ChartAreas[0].Area3DStyle.Rotation = newy; 

       newy = chart1.ChartAreas[0].Area3DStyle.Inclination + (e.Location.Y - mousePoint.Y); 
       if (newy < -90) 
        newy = -90; 
       if (newy > 90) 
        newy = 90; 

       chart1.ChartAreas[0].Area3DStyle.Inclination = newy; 

       mousePoint = e.Location; 
      } 
     } 
    } 
0

感謝您的代碼。

這在VB.NET:

Private Sub chart_drag(sender As Object, e As MouseEventArgs) Handles embChartTitrations_A_B.MouseMove 
     Dim intY As Integer 

     If e.Button = Windows.Forms.MouseButtons.Left Then 
      If pointStart = Nothing Then 
       pointStart = e.Location 
      Else 

       intY = embChartTitrations_A_B.ChartAreas(0).Area3DStyle.Rotation - Math.Round((e.Location.X - pointStart.X)/5) 
       If intY < -180 Then intY = -180 
       If intY > 180 Then intY = 180 

       embChartTitrations_A_B.ChartAreas(0).Area3DStyle.Rotation = intY 



       intY = embChartTitrations_A_B.ChartAreas(0).Area3DStyle.Inclination + Math.Round((e.Location.Y - pointStart.Y)/5) 
       If intY < -90 Then intY = -90 
       If intY > 90 Then intY = 90 

       embChartTitrations_A_B.ChartAreas(0).Area3DStyle.Inclination = intY 

       pointStart = e.Location 
      End If 

     End If 
    End Sub 

(我除以5鼠標的移動,因爲我覺得它允許圖表的更精確的旋轉)

由於

克里斯蒂安

0

對Ken的C#示例進行小小的更正和優化(否則我不是很差,我投了+1):

private Point _mousePos; 
private void chart_MouseMove(object sender, MouseEventArgs e) 
{ 
    if (e.Button != MouseButtons.Left) return; 
    if (!_mousePos.IsEmpty) 
    { 
     var style = chart.ChartAreas[0].Area3DStyle; 
     style.Rotation = Math.Min(180, Math.Max(-180, 
      style.Rotation - (e.Location.X - _mousePos.X))); 
     style.Inclination = Math.Min(90, Math.Max(-90, 
      style.Inclination + (e.Location.Y - _mousePos.Y))); 
    } 
    _mousePos = e.Location; 
}