我想通過將鼠標移動到其上方(左鍵按下)來旋轉關於其軸的Visual Studio 2010圖表。我在WPF中發現了很多例子,但在WinForms中沒有。如何使用Visual Basic.NET中的鼠標旋轉關於其軸的3D圖表
我在Visual Basic中編碼。
有人請指教我一個教程或示例代碼,將指向我在正確的方向。
謝謝!
我想通過將鼠標移動到其上方(左鍵按下)來旋轉關於其軸的Visual Studio 2010圖表。我在WPF中發現了很多例子,但在WinForms中沒有。如何使用Visual Basic.NET中的鼠標旋轉關於其軸的3D圖表
我在Visual Basic中編碼。
有人請指教我一個教程或示例代碼,將指向我在正確的方向。
謝謝!
試試這個:
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;
}
}
}
感謝您的代碼。
這在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鼠標的移動,因爲我覺得它允許圖表的更精確的旋轉)
由於
克里斯蒂安
對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;
}