Hello Alfonso,
Thank you for contacting Telerik Support.
ZoomGesture occurs when a zoom gesture was sent by a touch input device
only. However, it is possible to catch zooming on
MouseWheel event if the
ControlKey is pressed:
public
partial
class
Form1 : Form
{
bool
IsCtrlPressed =
false
;
public
Form1()
{
InitializeComponent();
BarSeries barSeries =
new
BarSeries(
"Performance"
,
"RepresentativeName"
);
barSeries.Name =
"Q1"
;
barSeries.DataPoints.Add(
new
CategoricalDataPoint(177,
"Harley"
));
barSeries.DataPoints.Add(
new
CategoricalDataPoint(128,
"White"
));
barSeries.DataPoints.Add(
new
CategoricalDataPoint(143,
"Smith"
));
barSeries.DataPoints.Add(
new
CategoricalDataPoint(111,
"Jones"
));
barSeries.DataPoints.Add(
new
CategoricalDataPoint(118,
"Marshall"
));
this
.radChartView1.Series.Add(barSeries);
BarSeries barSeries2 =
new
BarSeries(
"Performance"
,
"RepresentativeName"
);
barSeries2.Name =
"Q2"
;
barSeries2.DataPoints.Add(
new
CategoricalDataPoint(153,
"Harley"
));
barSeries2.DataPoints.Add(
new
CategoricalDataPoint(141,
"White"
));
barSeries2.DataPoints.Add(
new
CategoricalDataPoint(130,
"Smith"
));
barSeries2.DataPoints.Add(
new
CategoricalDataPoint(88,
"Jones"
));
barSeries2.DataPoints.Add(
new
CategoricalDataPoint(109,
"Marshall"
));
this
.radChartView1.Series.Add(barSeries2);
radChartView1.ShowPanZoom =
true
;
radChartView1.MouseWheel += radChartView1_MouseWheel;
radChartView1.KeyDown += radChartView1_KeyDown;
}
private
void
radChartView1_KeyDown(
object
sender, KeyEventArgs e)
{
if
(e.KeyCode==Keys.ControlKey)
{
IsCtrlPressed =
true
;
}
}
private
void
radChartView1_MouseWheel(
object
sender, MouseEventArgs e)
{
if
(e.Button == System.Windows.Forms.MouseButtons.None && IsCtrlPressed)
{
// radChartView1.Zoom(3, 1);
}
IsCtrlPressed =
false
;
}
}
On the other hand, you can make zoom to the
specific area of mouse location:
public
partial
class
Form1 : RadForm
{
private
Random rnd =
new
Random();
public
Form1()
{
InitializeComponent();
BarSeries bar =
new
BarSeries();
for
(
int
i = 0; i < 5; i++)
{
CategoricalDataPoint point =
new
CategoricalDataPoint();
point.Category = (
char
)(65 + i);
point.Value = i * 10;
bar.DataPoints.Add(point);
}
this
.radChartView1.Series.Add(bar);
this
.radChartView1.MouseWheel += radChartView1_MouseWheel;
}
private
void
radChartView1_MouseWheel(
object
sender, System.Windows.Forms.MouseEventArgs e)
{
SizeF newZoom =
new
SizeF(1f, 1f);
if
(e.Delta > 0)
{
// zoom in
newZoom.Width = (
float
)((IChartView)
this
.radChartView1.View).ZoomWidth * 1.1f;
}
else
{
// zoom out
float
xZoom = (
float
)((IChartView)
this
.radChartView1.View).ZoomWidth / 1.1f;
if
(xZoom >= 1)
{
newZoom.Width = xZoom;
}
else
{
newZoom.Width = 1;
// zoom out to max
}
}
double
oldStretchedAreaWidth =
this
.radChartView1.View.Viewport.Width * ((IChartView)
this
.radChartView1.View).ZoomWidth;
Point point = e.Location;
double
ratio = (point.X - ((IChartView)
this
.radChartView1.View).PlotOriginX) / oldStretchedAreaWidth;
this
.radChartView1.Zoom(newZoom.Width, newZoom.Height);
double
newStretchedAreaWidth =
this
.radChartView1.View.Viewport.Width * newZoom.Width;
double
panOffset = ratio * newStretchedAreaWidth - point.X;
this
.radChartView1.Pan(-panOffset, 0);
}
}
I hope this information helps. Should you have further questions, I would be glad to help.
Regards,
Desislava
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application.
Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>