如何在Visual Basic.NET中使用鼠标旋转3D图表的轴

时间:2013-02-03 18:33:36

标签: charts rotation

我想通过将鼠标移到它上面来旋转Visual Studio 2010图表(左键按下)。我在WPF中找到了很多例子,但在WinForms中没有。

我在Visual Basic中编码。

有人请指导我指向正确方向的教程或示例代码。

谢谢!

3 个答案:

答案 0 :(得分: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;
            }
        }
    }

答案 1 :(得分: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,因为我觉得它可以更精确地旋转图表)

由于

克里斯蒂安

答案 2 :(得分: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;
}