對TeeChart控件進行縮放功能添加
該功能是在已經繪圖之後
1,添加按鈕縮放功能
首先在視圖設計器上添加按鈕控件
爲按鈕添加響應函數
private void zoombtnClick(object sender, EventArgs e)
{
//double XMid = ((CursorTool)tChart1.Tools[0]).XValue;
double OldXMin = tChart1.Axes.Bottom.Minimum;
double OldXMax = tChart1.Axes.Bottom.Maximum;
double XMid = (OldXMin + OldXMax)/2;
double NewXMin = (XMid * 0.5 + OldXMin) / (1.5);
double NewXMax = (XMid * 0.5 + OldXMax) / (1.5);
tChart1.Axes.Bottom.SetMinMax(NewXMin, NewXMax);
}
private void undobtnClick(object sender, EventArgs e)
{
//double XMid = ((CursorTool)tChart1.Tools[0]).XValue;
double OldXMin = tChart1.Axes.Bottom.Minimum;
double OldXMax = tChart1.Axes.Bottom.Maximum;
double XMid = (OldXMin + OldXMax) / 2;
double NewXMin = (-XMid * 0.5 + OldXMin) / (0.5);
double NewXMax = (-XMid * 0.5 + OldXMax) / (0.5);
tChart1.Axes.Bottom.SetMinMax(NewXMin, NewXMax);
}
2.滾動縮放功能,這個功能中需要獲取鼠標位置,直接通過tchart1中的標籤位置獲取
double XMid = ((CursorTool)tChart1.Tools[0]).XValue;
爲TeeChart添加滾動響應,TeeChart.dll中沒有該事件,添加系統System.Windows.Forms.中的
this.tChart1.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.tChart1_MouseWheel);
相應的響應函數爲
private void tChart1_MouseWheel(object sender, MouseEventArgs e)
{
if (tChart1 != null)
{
double XMid = ((CursorTool)tChart1.Tools[0]).XValue;
if (e.Delta > 0)
{
double OldXMin = tChart1.Axes.Bottom.Minimum;
double OldXMax = tChart1.Axes.Bottom.Maximum;
double NewXMin = (XMid * 0.5 + OldXMin) / (1.5);
double NewXMax = (XMid * 0.5 + OldXMax) / (1.5);
tChart1.Axes.Bottom.SetMinMax(NewXMin, NewXMax);
}
else
{
double OldXMin = tChart1.Axes.Bottom.Minimum;
double OldXMax = tChart1.Axes.Bottom.Maximum;
double NewXMin = (-XMid * 0.5 + OldXMin) / (0.5);
double NewXMax = (-XMid * 0.5 + OldXMax) / (0.5);
tChart1.Axes.Bottom.SetMinMax(NewXMin, NewXMax);
}
}
}
感謝https://bbs.csdn.net/topics/110021766作者。