• 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");
           }
       }
  • 相关阅读:
    怎样获取节点的文本值
    怎样获取节点的名称
    怎样获取节点的类型
    Sublime Text 3
    ubuntu QT安装以及配置交叉编译环境
    Ubuntu下搭建NFS,并在开发板挂载
    Tk1上搭建turtlebot环境
    sudo dpkg --configure -a无法解决的问题
    ARM TK1 安装kinect驱动
    opencv2.4.9+vs2012安装配置
  • 原文地址:https://www.cnblogs.com/GaoHao518/p/14849500.html
Copyright © 2020-2023  润新知