Page 1 of 1
Controlling zoom/pan with the control key
Posted: Thu May 31, 2012 7:04 am
by 16060085
Hey
I need to redefine when to pan and zoom in a chart on a WinForm. Actually what I want is to use the zoom tool like normal (left click), but when the user press Ctrl while left clicking I want to pan the chart instead - and use the right click as a normal popup menu. I have solved the problem with disabling pan-funtionality on right click but how do I solve the "Ctrl+Left key" problem?
/Claus
Re: Controlling zoom/pan with the control key
Posted: Fri Jun 01, 2012 8:35 am
by 10050769
Hello Claus,
I suggest you use MouseDown and ModifierKeys method to achieve as you want Ctrl MouseLeft as do in next lines of code:
Code: Select all
public Form1()
{
InitializeComponent();
InitializeChart();
}
private void InitializeChart()
{
tChart1.Aspect.View3D = false;
Steema.TeeChart.Styles.Bar bar1 = new Bar(tChart1.Chart);
bar1.FillSampleValues();
bar1.SideMargins = false;
tChart1.MouseDown += new MouseEventHandler(tChart1_MouseDown);
}
void tChart1_MouseDown(object sender, MouseEventArgs e)
{
if (ModifierKeys == Keys.Control && e.Button == MouseButtons.Left)
{
tChart1.Zoom.Allow = false;
tChart1.Panning.MouseButton = MouseButtons.Left;
}
else
{
tChart1.Zoom.Allow = true;
tChart1.Panning.MouseButton = MouseButtons.Right;
}
}
Can you tell us if previous code works as you want? If you have any problems please, let me know.
Thanks,
Re: Controlling zoom/pan with the control key
Posted: Mon Jun 04, 2012 7:37 am
by 16060085
Hey
It did not work with MouseDown - but it works perfectly in a KeyUp/KeyDown combination - I was just missing the "tChart1.Panning.MouseButton" property, so now I have a working solution - thanks!
/Claus
Re: Controlling zoom/pan with the control key
Posted: Mon Jun 04, 2012 9:55 am
by 10050769
Hello Claus,
I am glad that your can solve your problem.
Thanks for your information,