.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> Silverlight >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Mouse wheel event in Silverlight 4.0

Posted By:Dhananjay Kumar       Posted Date: February 21, 2010    Points: 25    Category: Silverlight    URL: http://www.dotnetspark.com  

Mouse wheel event in Silverlight 4.0. Silverlight 4.0 has been introduced Mouse wheel event. Now on mouse wheel event can be captured. And the event can be raised for any silver light control
 

Objective

In this article, I am going to give a basic introduction of Mouse wheel event in Silverlight 4.0.

Introduction

Silverlight 4.0 has been introduced Mouse wheel event. Now on mouse wheel event can be captured. And the event can be raised for any silver light control. 

In below image you can see, MouseWheel event has been included.

1.gif

If you see the description above it is saying

"This event occurs, when user rotates the mouse wheel while pointer is over a UI Elements "

Sample

I have an image on my silver light page.


 
 
 



Output of above

2.gif

Now we are going to resize the image on mouse wheel event. 

Adding Mouse Wheel event with image

MyImage.MouseWheel += new MouseWheelEventHandler(mymousewheelevent);

Handling the event


 void mymousewheelevent(object sender, MouseWheelEventArgs e)
   {
 double  height = MyImage.Height;
 double  width = MyImage.Width;
 int delta = e.Delta;
  height += delta;
  width += delta / 2;
  MyImage.Height = height > 650 ? 400 : height;
  MyImage.Width = width > 600 ? 300 : width; 
  }



Explanation

  • Just saving current height and width in variables.
  • Using Delta method on event args , change could be captured.
  • Then just setting the dimension of image with some logic.

Output

Click on image and scroll the mouse ball. Image size will be change.

3.gif

So, we can attach the Mouse wheel event with any control. 

Conclusion

In this article, I gave basic introduction of MouseWheel event in Silverlight 4.0. Thanks for reading.

 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend