WPF 鼠标移动到图片变大,移开还原,单击触发事件效果
2024-10-19 12:03:22
<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" ); } } |
最新文章
- 从阿里巴巴IPO联想到创始人和资方关系
- 多媒体(1):MCI接口编程
- lua面试基础知识
- 编写一个Car类,具有String类型的属性品牌,具有功能drive; 定义其子类Aodi和Benchi,具有属性:价格、型号;具有功能:变速; 定义主类E,在其main方法中分别创建Aodi和Benchi的对象并测试对象的特 性。
- Vue 模板
- Jmeter初步使用三--使用jmeter自身录制脚本
- BZOJ 1625: [Usaco2007 Dec]宝石手镯( dp )
- spring的jar各包作用
- 【easy】653. Two Sum IV - Input is a BST
- [C][代码实例]冒泡排序
- nodejs stream 手册学习
- Java并发—synchronized关键字
- Spring MVC 学习 之 - 配置简单demo
- Vijos P1002 过河 (NOIP提高组2005)
- 理解JavaScript原始类型和引用类型
- Centos 7 快速安装 Docker
- AngularJS之页面跳转Route
- Java并发(5)- ReentrantLock与AQS
- vlan 配置
- Day2-VIM(一):移动
热门文章
- Three---面向对象与面向过程/属性和变量/关于self/一些魔法方法的使用/继承/super方法/多态
- Go 语言图片处理简明教程
- 杀死 Windows 某个端口
- 牛客IOI周赛26-提高组 A. 逆序对
- Star (欧拉函数)
- Swift中的Result 类型的简单介绍
- Python实现XMind测试用例快速转Excel用例
- KingbaseES 全局索引
- SpringBoot使用自定义注解+AOP+Redis实现接口限流
- ProxySQL(9):ProxySQL的查询缓存功能