Geeks With Blogs
DotNet Snippets Silverlight and C#

Hi Guys,

I have basic sample on how to use some features of mouse events in Silverlight.

The picture.

The Mouse Activity Log is to record the all activity done on the projects. My simple snippets on how to add on the textbox is:

        protected void MessageLog(string msg)
        {
            txtMouseLog.Text += msg;
        }
 

For the Mouse Wheel sample this is the snippets:

        private void chkMouseWheel_Checked(object sender, RoutedEventArgs e)
        {
            image1.MouseWheel += new MouseWheelEventHandler(image1_MouseWheel);
        }
 
        void image1_MouseWheel(object sender, MouseWheelEventArgs e)
        {
            ImgScale.ScaleX = e.Delta > 0 ? ImgScale.ScaleX * 1.5 : ImgScale.ScaleX * 0.8;
            ImgScale.ScaleY = e.Delta > 0 ? ImgScale.ScaleY * 1.5 : ImgScale.ScaleY * 0.8;
 
            e.Handled = true;
        }
 
 And the XAML:
       <Image Height="139" Name="image1" Stretch="Fill" Width="178" Source="/GBLOgs1;component/Images/Sunset.jpg">
           <Image.RenderTransform>
                <ScaleTransform x:Name="ImgScale"></ScaleTransform>
           </Image.RenderTransform>
       </Image
 
 
I have also the showing of mouse position:
 
        private void Mouse_MouseMove(object sender, MouseEventArgs e)
        {
            Point point = e.GetPosition(this);
            lblMouseLocation.Content = "X: " + point.X + "and Y: " + point.Y;
        }
 
        private void checkBox1_Checked(object sender, RoutedEventArgs e)
        {
            lblMouseLocation.Visibility = Visibility.Visible;
            MessageLog("Mouse Location Visible\n");
        }
 
        private void checkBox1_Unchecked(object sender, RoutedEventArgs e)
        {
            lblMouseLocation.Visibility = Visibility.Collapsed;
            MessageLog("Mouse Location Collapsed\n");
       
 
 And even the counting of clicked event:
 
        int clicked = 0;
        private void LayoutRoot_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            Point point = e.GetPosition(this);
            clicked++;
 
            string msg = "Mouse Clicked " + clicked.ToString() + " time(s) " +
                                    "Mouse Location X and Y: " + point.X + " " + point.Y + "\n";
 
            MessageLog(msg);
        }
 

 

And now the result of above snippets. Happy Programming.

Posted on Sunday, May 16, 2010 11:40 PM C# , Silverlight | Back to top


Comments on this post: Basic Mouse Features in Silverlight

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Sayre Collado | Powered by: GeeksWithBlogs.net