鼠标在一段时间内静止贴出提示标签的效果

2024-06-17 08:08

本文主要是介绍鼠标在一段时间内静止贴出提示标签的效果,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

后台代码:<span style="font-family: Arial, Helvetica, sans-serif;">public partial class MainWindow : Window</span>
    {public MainWindow(){InitializeComponent();}DispatcherTimer dtimer = new DispatcherTimer();Point p;private void Grid_MouseEnter(object sender, MouseEventArgs e){Point p = Mouse.GetPosition(e.Source as IInputElement);textBox1.Text = p.X.ToString() + ", " + p.Y.ToString();}#region 鼠标悬浮在按钮上1sprivate void startTimer(object sender, MouseEventArgs e){if (dtimer.IsEnabled == true){dtimer.Stop();}dtimer = new DispatcherTimer();dtimer.Interval = TimeSpan.FromMilliseconds(1000);dtimer.Tick += show;dtimer.Start();dtimer.Tag = sender;p = e.GetPosition(e.Source as IInputElement);}private void stopTimer(){if (dtimer.IsEnabled == true){dtimer.Stop();}}private void show(object o, EventArgs e){DispatcherTimer objTimer = (DispatcherTimer)o;Button objButton = (Button)objTimer.Tag;MessageBox.Show(p.X.ToString() + "," + p.Y.ToString() + "\n" + objButton.Content.ToString());dtimer.Stop();}#endregion#region 各个按钮的悬浮事件、鼠标离开事件private void btnOK_MouseMove(object sender, MouseEventArgs e){startTimer(sender, e);}private void btnOK_MouseLeave(object sender, MouseEventArgs e){stopTimer();}private void button1_MouseMove(object sender, MouseEventArgs e){startTimer(sender, e);}private void button1_MouseLeave(object sender, MouseEventArgs e){stopTimer();}#endregion}
<span style="font-family: Arial, Helvetica, sans-serif;">前台代码:</span><span style="font-family: Arial, Helvetica, sans-serif;"><pre name="code" class="html"><Window x:Class="MouseEnterMakeTag.MainWindow"</span>
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"Title="MainWindow" Height="350" Width="525"  ><Grid MouseEnter="Grid_MouseEnter"><Button Content="按钮1" Height="61" HorizontalAlignment="Left" Margin="12,12,0,0" Name="btnOK" VerticalAlignment="Top" Width="61" MouseMove="btnOK_MouseMove" MouseLeave="btnOK_MouseLeave" /><TextBox Height="23" HorizontalAlignment="Left" Margin="371,12,0,0" Name="textBox1" VerticalAlignment="Top" Width="120" /><Button Content="按钮2" Height="61" HorizontalAlignment="Left" Margin="12,79,0,0" Name="btnCancel" VerticalAlignment="Top" Width="61" MouseMove="button1_MouseMove" MouseLeave="button1_MouseLeave" /></Grid>
</Window>


 

这篇关于鼠标在一段时间内静止贴出提示标签的效果的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1068901

相关文章

CSS去除a标签的下划线的几种方法

《CSS去除a标签的下划线的几种方法》本文给大家分享在CSS中,去除a标签(超链接)的下划线的几种方法,本文给大家介绍的非常详细,感兴趣的朋友一起看看吧... 在 css 中,去除a标签(超链接)的下划线主要有以下几种方法:使用text-decoration属性通用选择器设置:使用a标签选择器,将tex

MyBatis 动态 SQL 优化之标签的实战与技巧(常见用法)

《MyBatis动态SQL优化之标签的实战与技巧(常见用法)》本文通过详细的示例和实际应用场景,介绍了如何有效利用这些标签来优化MyBatis配置,提升开发效率,确保SQL的高效执行和安全性,感... 目录动态SQL详解一、动态SQL的核心概念1.1 什么是动态SQL?1.2 动态SQL的优点1.3 动态S

Python基于wxPython和FFmpeg开发一个视频标签工具

《Python基于wxPython和FFmpeg开发一个视频标签工具》在当今数字媒体时代,视频内容的管理和标记变得越来越重要,无论是研究人员需要对实验视频进行时间点标记,还是个人用户希望对家庭视频进行... 目录引言1. 应用概述2. 技术栈分析2.1 核心库和模块2.2 wxpython作为GUI选择的优

mss32.dll文件丢失怎么办? 电脑提示mss32.dll丢失的多种修复方法

《mss32.dll文件丢失怎么办?电脑提示mss32.dll丢失的多种修复方法》最近,很多电脑用户可能遇到了mss32.dll文件丢失的问题,导致一些应用程序无法正常启动,那么,如何修复这个问题呢... 在电脑常年累月的使用过程中,偶尔会遇到一些问题令人头疼。像是某个程序尝试运行时,系统突然弹出一个错误提

电脑提示找不到openal32.dll文件怎么办? openal32.dll丢失完美修复方法

《电脑提示找不到openal32.dll文件怎么办?openal32.dll丢失完美修复方法》openal32.dll是一种重要的系统文件,当它丢失时,会给我们的电脑带来很大的困扰,很多人都曾经遇到... 在使用电脑过程中,我们常常会遇到一些.dll文件丢失的问题,而openal32.dll的丢失是其中比较

电脑提示msvcp90.dll缺少怎么办? MSVCP90.dll文件丢失的修复方法

《电脑提示msvcp90.dll缺少怎么办?MSVCP90.dll文件丢失的修复方法》今天我想和大家分享的主题是关于在使用软件时遇到的一个问题——msvcp90.dll丢失,相信很多老师在使用电脑时... 在计算机使用过程中,可能会遇到 MSVCP90.dll 丢失的问题。MSVCP90.dll 是 Mic

电脑开机提示krpt.dll丢失怎么解决? krpt.dll文件缺失的多种解决办法

《电脑开机提示krpt.dll丢失怎么解决?krpt.dll文件缺失的多种解决办法》krpt.dll是Windows操作系统中的一个动态链接库文件,它对于系统的正常运行起着重要的作用,本文将详细介绍... 在使用 Windows 操作系统的过程中,用户有时会遇到各种错误提示,其中“找不到 krpt.dll”

Maven pom.xml文件中build,plugin标签的使用小结

《Mavenpom.xml文件中build,plugin标签的使用小结》本文主要介绍了Mavenpom.xml文件中build,plugin标签的使用小结,文中通过示例代码介绍的非常详细,对大家的学... 目录<build> 标签Plugins插件<build> 标签<build> 标签是 pom.XML

CSS模拟 html 的 title 属性(鼠标悬浮显示提示文字效果)

《CSS模拟html的title属性(鼠标悬浮显示提示文字效果)》:本文主要介绍了如何使用CSS模拟HTML的title属性,通过鼠标悬浮显示提示文字效果,通过设置`.tipBox`和`.tipBox.tipContent`的样式,实现了提示内容的隐藏和显示,详细内容请阅读本文,希望能对你有所帮助... 效

Vue项目的甘特图组件之dhtmlx-gantt使用教程和实现效果展示(推荐)

《Vue项目的甘特图组件之dhtmlx-gantt使用教程和实现效果展示(推荐)》文章介绍了如何使用dhtmlx-gantt组件来实现公司的甘特图需求,并提供了一个简单的Vue组件示例,文章还分享了一... 目录一、首先 npm 安装插件二、创建一个vue组件三、业务页面内 引用自定义组件:四、dhtmlx