Visual Studio 2010チャートの上にマウスを移動して(左ボタンを下に)、その軸を中心に回転させたいと思います。WPFには多くの例がありますが、WinFormsにはありません。
VisualBasicでコーディングしています。
誰かが私を正しい方向に向けるチュートリアルまたはサンプルコードに私を導いてくれませんか。
ありがとう!
これを試して:
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;
}
}
}
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;
}