Devin Rader's Blog
I write the code...

Using the Mouse Wheel to zoom in and out of the UltraChart

Tuesday, February 07, 2006 8:01 AM

Heres a small code snippet that demonstrates how to use the MouseWheel event to change the scale of the UltraChart.  As the user scrolls forward or backward, the chart zooms in or out.  Also notice that in order for the chart control to capture the MouseWheel event it has to have Focus, so you can just use the MouseEnter event to give the chart control focus as soon as the mouse enters the control.

private void ultraChart1_MouseWheel(object sender, MouseEventArgs e)
{
    System.Diagnostics.Debug.WriteLine(e.Delta)
;
    if 
(e.Delta<0)
    {
        
if (this.ultraChart1.Axis.X.ScrollScale.Scale<1)
        {
            
this.ultraChart1.Axis.X.ScrollScale.Scale+=.02;
            this
.ultraChart1.Axis.Y.ScrollScale.Scale+=.02;
        
}
        
return;
    
}
    
    
if(e.Delta>0)
    {
        
if (this.ultraChart1.Axis.X.ScrollScale.Scale>0)
        {
            
this.ultraChart1.Axis.X.ScrollScale.Scale-=.02;
            this
.ultraChart1.Axis.Y.ScrollScale.Scale-=.02;
        
}

        
return;
    
}
    
}

private void ultraChart1_MouseEnter(object sender, System.EventArgs e)
{
    
this.ultraChart1.Focus();
}

Feedback

# re: Using the Mouse Wheel to zoom in and out of the UltraChart

Hello,
I recommend testing bth properties for being between 0 and one, otherwise youll get an <ClassName id="ref-11">System.ArgumentOutOfRangeException</ClassName>
<Message id="ref-12">The value of this property must be between 0,00 and 1,00.</Message>
if the user zooms in manually in one of the axis.
Have a nice weekend,
Caroline 2/10/2006 8:04 AM | Caroline

# re: Using the Mouse Wheel to zoom in and out of the UltraChart

Excellent point...yes, you definitly should test both Scales. 2/10/2006 8:06 AM | Devin

# re: Using the Mouse Wheel to zoom in and out of the UltraChart

Still another comment:
- if you test for the properties to be >= 0.02 and <= 0.98 you avoid also crashes if the user zoomed manually and differently on the axes.

- in composite charts, you have to set these properties to the Axis elements, like this for example: if(this.ultraChart1.Axis.X.ScrollScale.Visible == true)
{
if (e.Delta<0)
{
if (this.ultraChart1.Axis.X.ScrollScale.Scale <= 0.98)
{ this.ultraChart1.Axis.X.ScrollScale.Scale += .02;
}
this.ultraChart1.InvalidateLayers();
this.ultraChart1.Refresh();
return;
}
The Invalidate() and Refresh() are needed because otherwise the zooming will occur only if you leave the control right after to mouse-wheeling.
Greetings, have fun,
Caroline 2/13/2006 4:52 AM | Caroline

# re: Using the Mouse Wheel to zoom in and out of the UltraChart

Hi Devin ,

Am using Infrgistics NetAdvantage_NET_20073_CLR20 version(Trail Version)
Am unable to find MouseWheel event
1.Do i need at refer for any other dll
2.Do i need to update with latest version

how to generate MouseWheel event please help me out from issue

Thanks in Advance 4/2/2009 5:31 PM | Ravi Kumar

# re: Using the Mouse Wheel to zoom in and out of the UltraChart

Hey Ravi,

Try attaching to the event through code.
I couldn't see the event in the designtime editor myself but it should be available if you try in your code. 4/6/2009 1:50 AM | Kristof

Post a comment