0

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

我正在用 Visual Basic 编码。

有人可以指导我看一个教程或示例代码,它们将为我指明正确的方向。

谢谢!

4

3 回答 3

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;
            }
        }
    }
于 2013-08-06T19:32:45.120 回答
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,因为我觉得它可以更精确地旋转图表)

谢谢

克里斯蒂安

于 2014-02-18T12:10:56.527 回答
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;
}
于 2016-09-14T19:32:35.017 回答