Zoom/Unzoom using mouse button click
Zoom/Unzoom using mouse button click
Hi,
I want to disable the zooming and unzooming using the dragging of mouse downwords and upwords. How can i do it?
Instead i want to add two buttons in my toolbar say Zoom button and Unzoom button.
Now when user clicked the Zoom button in the toolbar, the mouse cursor should get changed to a zoom cursor(some visual indication). After that if user drag the mouse in any direction in a perticular area of the chart control that area should get zoomed.
Similarly when user clicks the Unzoom button in the tool bar the mouse cursor should change to Unzoom cursor. After that, if user clicks the mouse button then the chart control should get unzoomed. May be by step by step unzoom or at a time unzoom.
How can i achive this using TeeChart control?
Thanks in advance for your help.
Regards,
Avijit
I want to disable the zooming and unzooming using the dragging of mouse downwords and upwords. How can i do it?
Instead i want to add two buttons in my toolbar say Zoom button and Unzoom button.
Now when user clicked the Zoom button in the toolbar, the mouse cursor should get changed to a zoom cursor(some visual indication). After that if user drag the mouse in any direction in a perticular area of the chart control that area should get zoomed.
Similarly when user clicks the Unzoom button in the tool bar the mouse cursor should change to Unzoom cursor. After that, if user clicks the mouse button then the chart control should get unzoomed. May be by step by step unzoom or at a time unzoom.
How can i achive this using TeeChart control?
Thanks in advance for your help.
Regards,
Avijit
Re: Zoom/Unzoom using mouse button click
Hello Avijit,
I could make a simple example that I think solve your problem. Please check that next example works as you want:
I hope will helps.
Thanks,
I could make a simple example that I think solve your problem. Please check that next example works as you want:
Code: Select all
Steema.TeeChart.Styles.Line line1;
bool zooming;
private Rectangle rect;
private void InitializeChart()
{
line1 = new Steema.TeeChart.Styles.Line(tChart1.Chart);
line1.FillSampleValues(20);
tChart1.MouseDown += new MouseEventHandler(tChart1_MouseDown);
tChart1.MouseUp += new MouseEventHandler(tChart1_MouseUp);
tChart1.MouseMove += new MouseEventHandler(tChart1_MouseMove);
zooming = false;
tChart1.Zoom.Allow = false;
tChart1.Zoom.History = checkBox1.Checked;
}
void tChart1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
if (zooming && (rect.X != 0) && (rect.Y != 0))
{
rect.Width = e.X - rect.Left;
rect.Height = e.Y - rect.Top;
}
Rectangle tmpRect = rect;
if (tmpRect.Width < 0)
{
tmpRect.X = rect.X - Math.Abs(rect.Width);
tmpRect.Width = x - tmpRect.X;
}
if (rect.Height < 0)
{
tmpRect.Y = rect.Y - Math.Abs(rect.Height);
tmpRect.Height = y - tmpRect.Y;
}
tChart1.Graphics3D.Brush.Transparency = 100;
tChart1.Graphics3D.Rectangle(tmpRect);
}
tChart1.Invalidate();
}
void tChart1_MouseUp(object sender, MouseEventArgs e)
{
rect.Width = e.X - rect.Left;
rect.Height = e.Y - rect.Top;
if (zooming)
{
tChart1.Zoom.ZoomRect(rect);
rect = new Rectangle(0, 0, 0, 0);
}
}
private int x, y;
void tChart1_MouseDown(object sender, MouseEventArgs e)
{
rect = new Rectangle(e.X, e.Y, 0, 0);
x = e.X;
y = e.Y;
}
private void button1_Click(object sender, EventArgs e)
{
zooming = true;
}
private void button3_Click(object sender, EventArgs e)
{
tChart1.Zoom.Undo();
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
tChart1.Zoom.History = checkBox1.Checked;
}
Thanks,
Best Regards,
Sandra Pazos / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
Re: Zoom/Unzoom using mouse button click
Hi Sandra,
Thanks for your reply.
One very important thing that i should have mentioned in my previous post is - i cannot invalidate or refresh the TeeChart control during MouseMove event or any event that will occur very frequently. Because we are showing huge amount of data at a time and if we call Invalidate or refresh it will be a very big performance issue. So i did not yet tested your code in my application but it looks like it will work if we can just remove the invalidate call from the MoveMove event. May be i should use ReversibleRectangle?? Any suggetion?
Regards,
Avijit
Thanks for your reply.
One very important thing that i should have mentioned in my previous post is - i cannot invalidate or refresh the TeeChart control during MouseMove event or any event that will occur very frequently. Because we are showing huge amount of data at a time and if we call Invalidate or refresh it will be a very big performance issue. So i did not yet tested your code in my application but it looks like it will work if we can just remove the invalidate call from the MoveMove event. May be i should use ReversibleRectangle?? Any suggetion?
Regards,
Avijit
Re: Zoom/Unzoom using mouse button click
Hello Avijit,
I recomend two thinks:
First, you have an option of RebercibleRectangle. Other, you could not paint rectangle, you only have deleted all the code that you use for draw of rectangle(tmpRect).If you choose this option, performance are smaller and Zoom will continue doing.
I hope will helps.
Thanks,
I recomend two thinks:
First, you have an option of RebercibleRectangle. Other, you could not paint rectangle, you only have deleted all the code that you use for draw of rectangle(tmpRect).If you choose this option, performance are smaller and Zoom will continue doing.
I hope will helps.
Thanks,
Best Regards,
Sandra Pazos / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
Re: Zoom/Unzoom using mouse button click
Hi Sandra,
I have one query -
The code you have written below - in the Unzoom part if i call Undo() function directly then the control is getting reset to its normal view at a time irrespective of the History zoom checkbox.
How to unzoom step by step?
Regards,
Avijit
I have one query -
The code you have written below - in the Unzoom part if i call Undo() function directly then the control is getting reset to its normal view at a time irrespective of the History zoom checkbox.
How to unzoom step by step?
Regards,
Avijit
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Re: Zoom/Unzoom using mouse button click
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Re: Zoom/Unzoom using mouse button click
Hi Avijit,
For completeness, for being able to unzoom step by step you need to have zoomed with History set to true.
For completeness, for being able to unzoom step by step you need to have zoomed with History set to true.
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
Re: Zoom/Unzoom using mouse button click
Hi Narcis,
Thanks for your reply.
After trying few things i have decided to not to use the normal zooming functionality that has been provided by TeeChart.
I have set -
TeeChart.Zoom.Allow = false;
Instead i am using the SetMinMax function of the Axis for zooming.
Now zooming is working as i expected.
But with these approach i am not able to get the advantage of History Unzooming.
I have 10 custom Y axis so that each data series can have its own place without overlaping with each other.
Please let me know how can i achieve the History zooming i that case.
Regards,
Avijit
Thanks for your reply.
After trying few things i have decided to not to use the normal zooming functionality that has been provided by TeeChart.
I have set -
TeeChart.Zoom.Allow = false;
Instead i am using the SetMinMax function of the Axis for zooming.
Now zooming is working as i expected.
But with these approach i am not able to get the advantage of History Unzooming.
I have 10 custom Y axis so that each data series can have its own place without overlaping with each other.
Please let me know how can i achieve the History zooming i that case.
Regards,
Avijit
Re: Zoom/Unzoom using mouse button click
Hi Avijit,
In that case you'll have to store you own history. You could have a two dimension array for each custom axis. When you zoom in, you add the min and max of each axis before zooming so you will be able to restore them in the zoom out procedure.
In that case you'll have to store you own history. You could have a two dimension array for each custom axis. When you zoom in, you add the min and max of each axis before zooming so you will be able to restore them in the zoom out procedure.
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
-
- Newbie
- Posts: 8
- Joined: Wed Nov 04, 2009 12:00 am
Re: Zoom/Unzoom using mouse button click
Hi,
I am using the code you gave above but i am having a problem when i selected zoom in and i click on the chart. The chart will become blank and my line is missing. Only when i click on zoom out then i come back again. Please help me out with that by providing me the code. Thanks
Regards,
Nicholas
I am using the code you gave above but i am having a problem when i selected zoom in and i click on the chart. The chart will become blank and my line is missing. Only when i click on zoom out then i come back again. Please help me out with that by providing me the code. Thanks
Regards,
Nicholas
Re: Zoom/Unzoom using mouse button click
Hi,
I also got the same problem once.
I think you have to check the mouse down and mouse up value before even doing anything with zoom.
If these two values are same you need not go ahead and zoom. Just return from there.
hope this will solve the problem.
Regards,
Avijit
I also got the same problem once.
I think you have to check the mouse down and mouse up value before even doing anything with zoom.
If these two values are same you need not go ahead and zoom. Just return from there.
hope this will solve the problem.
Regards,
Avijit
-
- Newbie
- Posts: 8
- Joined: Wed Nov 04, 2009 12:00 am
Re: Zoom/Unzoom using mouse button click
Hi Avijit,
I am new to using teechart. Is it checking the x and y value of MouseDown, and rect.Width and rect.Height of MouseUp? If u can, please give me a simple code. Sorry and thanks alot.
Regards,
Nicholas
I am new to using teechart. Is it checking the x and y value of MouseDown, and rect.Width and rect.Height of MouseUp? If u can, please give me a simple code. Sorry and thanks alot.
Regards,
Nicholas
Re: Zoom/Unzoom using mouse button click
Hi,
See below the sample code.
Hope this will help.
Regards,
Avijit
See below the sample code.
Code: Select all
int ZoomX, ZoomY;
private void tChart1_MouseDown(object sender, MouseEventArgs e)
{
if (tChart1.Series.Count <= 0) return;
if (e.Button == MouseButtons.Left)
{
ZoomX = e.X;
ZoomY = e.Y;
}
}
private void tChart1_MouseUp(object sender, MouseEventArgs e)
{
if (e.X == ZoomX && e.Y == ZoomY) return;
}
Regards,
Avijit
-
- Newbie
- Posts: 8
- Joined: Wed Nov 04, 2009 12:00 am
Re: Zoom/Unzoom using mouse button click
Hi Avijit,
Thanks alot. It's work. Thank you.
Regards,
Nicholas
Thanks alot. It's work. Thank you.
Regards,
Nicholas