あなたがしたいと思う
MouseWheelイベントを使用します。あなたのグラフを拡大表示できるようにしてください。たとえば:
chart1.ChartAreas[0].AxisX.ScaleView.Zoomable = true;
次にマウスホイールイベントにアクセス:
private void chData_MouseWheel(object sender, MouseEventArgs e)
{
try
{
if (e.Delta < 0)
{
chart1.ChartAreas[0].AxisX.ScaleView.ZoomReset();
chart1.ChartAreas[0].AxisY.ScaleView.ZoomReset();
}
if (e.Delta > 0)
{
double xMin = chart1.ChartAreas[0].AxisX.ScaleView.ViewMinimum;
double xMax = chart1.ChartAreas[0].AxisX.ScaleView.ViewMaximum;
double yMin = chart1.ChartAreas[0].AxisY.ScaleView.ViewMinimum;
double yMax = chart1.ChartAreas[0].AxisY.ScaleView.ViewMaximum;
double posXStart = chart1.ChartAreas[0].AxisX.PixelPositionToValue(e.Location.X) - (xMax - xMin)/4;
double posXFinish = chart1.ChartAreas[0].AxisX.PixelPositionToValue(e.Location.X) + (xMax - xMin)/4;
double posYStart = chart1.ChartAreas[0].AxisY.PixelPositionToValue(e.Location.Y) - (yMax - yMin)/4;
double posYFinish = chart1.ChartAreas[0].AxisY.PixelPositionToValue(e.Location.Y) + (yMax - yMin)/4;
chart1.ChartAreas[0].AxisX.ScaleView.Zoom(posXStart, posXFinish);
chart1.ChartAreas[0].AxisY.ScaleView.Zoom(posYStart, posYFinish);
}
}
catch { }
}
は、これを行うのクリーンな方法は、おそらくありますが、それはそこにあります。 e.Delta
プロパティは、あなたがやった車輪のスクロール回数を表しており、便利です。このコードを使用すると、スクロールしても元のサイズに戻るだけです。
希望すると便利です。
これは私のためにはうまくいった。ありがとう! – crocboy
これは私のためには機能しません。チャートのマウスホイールイベントは発生していません。 –
明らかに、これを行うためには、これを行う必要があります。void friendChart_MouseLeave(オブジェクト送信者、EventArgs e) { if(friendChart.Focused) friendChart.Parent.Focus(); } void friendChart_MouseEnter(オブジェクト送信者、EventArgs e) { if(!friendChart.Focused) friendChart.Focus(); } '[マウスホイールイベントが発砲しない](http://stackoverflow.com/questions/13782763/mousewheel-event-not-firing) –