zoukankan      html  css  js  c++  java
  • WPF 鼠标移动到图片变大,移开还原,单击触发事件效果

    <Grid>
            <Canvas x:Name="LayoutRoot">
                <Image Cursor="Hand" MouseLeftButtonDown="imgLogo1_MouseLeftButtonDown" MouseEnter="imgLogo1_MouseEnter" 
                       MouseLeave="imgLogo1_MouseLeave" Canvas.ZIndex="1" x:Name="imgLogo1" Canvas.Left="100" 
                       Canvas.Top="60" Height="100" Source="Image/Picture.jpg">
                    <Image.RenderTransform>
                        <ScaleTransform x:Name="LogoScale" CenterX="90" CenterY="96">
    
                        </ScaleTransform>
                    </Image.RenderTransform>
                </Image>
            </Canvas>
        </Grid>
    

      

     public partial class Window8 : Window
        {
            public Window8()
            {
                InitializeComponent();
                timer = new System.Windows.Threading.DispatcherTimer();
                timer.Interval = TimeSpan.FromMilliseconds(50);
                timer.Tick += new EventHandler(timer_Tick);
            }
    
            private System.Windows.Threading.DispatcherTimer timer;
            private ScaleDirection scaleDirection ;
           
    
            void timer_Tick(object sender, EventArgs e)
            {
                AdjustScale(scaleDirection, LogoScale);
            }
    
            void AdjustScale(ScaleDirection scaleDirection, ScaleTransform scale)
            {
                if (scaleDirection == ScaleDirection.Down)
                {
                    if (scale.ScaleX < 1.3)
                    {
                        scale.ScaleX += 0.05; scale.ScaleY += 0.05;
                    }
                    else
                        timer.Stop();
                }
                else
                {
                    if (scale.ScaleX > 1.0)
                    {
                        scale.ScaleX -= 0.05;
                        scale.ScaleY -= 0.05;
                    }
                    else
                        timer.Stop();
                }
            }
    
            enum ScaleDirection
            {
                Up,
                Down
            }
    
            private void imgLogo1_MouseEnter(object sender, MouseEventArgs e)
            {
                scaleDirection = ScaleDirection.Down;
                timer.Start();
            }
    
            private void imgLogo1_MouseLeave(object sender, MouseEventArgs e)
            {
                scaleDirection = ScaleDirection.Up;
                timer.Start();
            }
    
            private void imgLogo1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
            {
                MessageBox.Show("test");
            }
        }

    原文:http://www.csharpwin.com/dotnetspace/10339r6936.shtml

    编辑器加载中...

  • 相关阅读:
    56.字符流中第一个不重复的数
    55.表示数值的字符串
    54.正则表达式匹配
    53.构建乘积数组
    52.数组中重复的数字
    51.把字符串转化为整数
    50.不用加减乘除求和
    49.求1+2+3+.......+n
    The great pleasure in life is doing what people say you cannot do.
    mkcert本地 HTTPS 加密证书生成工具
  • 原文地址:https://www.cnblogs.com/linlf03/p/2150559.html
Copyright © 2011-2022 走看看