WPF备忘录(2)WPF获取和设置鼠标位置与progressbar的使用方法
一、WPF 中获取和设置鼠标位置
方法一:WPF方法
Point p = Mouse.GetPosition(e.Source as FrameworkElement); Point p = (e.Source as FrameworkElement).PointToScreen(pp);
方法二: API方法
/// <summary>
/// 设置鼠标的坐标
/// </summary>
/// <param name="x">横坐标</param>
/// <param name="y">纵坐标</param> [DllImport("User32")] public extern static void SetCursorPos(int x, int y);
public struct POINT
{
public int X;
public int Y;
public POINT(int x, int y)
{
this.X = x;
this.Y = y;
} } /// <summary>
/// 获取鼠标的坐标
/// </summary>
/// <param name="lpPoint">传址参数,坐标point类型</param>
/// <returns>获取成功返回真</returns> [DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool GetCursorPos(out POINT pt); private void Window_MouseMove(object sender, MouseEventArgs e)
{
POINT p = new POINT();
if (GetCursorPos(out p))//API方法
{
txtStat.Text = string.Format("X:{0} Y:{1}", p.X, p.Y);
}
}
二、 WPF中实现实时更新progressbar
实现实时更新ProgressBar貌似有很多方法,我搜索的很多资料都要用线程,觉得还是有点儿麻烦,最后在国外的技术论坛上看到
一个用代理解决的方法,下面就是我的调试过程:
private delegate void UpdateProgressBarDelegate(System.Windows.DependencyProperty dp,
Object value);
private void Process()
{
//Configure the ProgressBar
ProgressBar1.Minimum = 0;
ProgressBar1.Maximum = short.MaxValue;
ProgressBar1.Value = 0;
//Stores the value of the ProgressBar
double value = 0;
UpdateProgressBarDelegate updatePbDelegate = new UpdateProgressBarDelegate(ProgressBar1.SetValue);
//Tight Loop: Loop until the ProgressBar.Value reaches the max
do
{
value += 1;
Dispatcher.Invoke(updatePbDelegate,
System.Windows.Threading.DispatcherPriority.Background,
new object[] { ProgressBar.ValueProperty, value });
}
while (ProgressBar1.Value != ProgressBar1.Maximum);
}
前台:
<ProgressBar Grid.Row="1" Height="20" Width="200" Margin="0,4,0,0" Name="ProgressBar1" HorizontalAlignment="Center" VerticalAlignment="top" />
效果:
方法二:使用定时器
public Window1()
{
InitializeComponent(); DispatcherTimer _mainTimer = new DispatcherTimer();
_mainTimer.Interval = TimeSpan.FromSeconds();
_mainTimer.Tick += new EventHandler(_mainTimer_Tick);
_mainTimer.IsEnabled = true; }
void _mainTimer_Tick(object sender, EventArgs e)
{
if (progressBar2.Value == progressBar1.Maximum)
progressBar2.Value = ; progressBar2.Value++;
}
WPF备忘录(2)WPF获取和设置鼠标位置与progressbar的使用方法的更多相关文章
- WPF获取和设置鼠标位置与progressbar的使用方法
一.WPF 中获取和设置鼠标位置 方法一:WPF方法 Point p = Mouse.GetPosition(e.Source as FrameworkElement); Point p = (e.S ...
- javascript获取以及设置光标位置
一. 获取光标位置: // 获取光标位置 function getCursortPosition (textDom) { var cursorPos = 0; if (document.selecti ...
- OpenCV获取与设置像素点的值的几个方法
Title: OpenCV OpenCV像素值的获取与设置 Fn 1 : 使用 Mat 中对矩阵元素的地址定位的知识 (参考博文:OpenCV中对Mat里面depth,dims,channels,st ...
- unity获取ugui上鼠标位置
public class GetMousePos : MonoBehaviour { public Canvas canvas;//画布 private RectTransform rectTrans ...
- $(window).scrollTop() 获取当前的鼠标位置 offset.left()指定标签在html中的坐标 offset.top() 指定标签在html中的坐标position() 指定标签相对父(relative)标签的坐标
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- WPF 程序鼠标在窗口之外的时候,控件拿到的鼠标位置在哪里?
原文:WPF 程序鼠标在窗口之外的时候,控件拿到的鼠标位置在哪里? 在 WPF 程序中,我们有 Mouse.GetPosition(IInputElement relativeTo) 方法可以拿到鼠标 ...
- 使用C#模拟键盘输入、鼠标移动和点击、设置光标位置及控制应用程序的显示
1.模拟键盘输入(SendKeys) 功能:将一个或多个按键消息发送到活动窗口,就如同在键盘上进行输入一样. 语法:SendKeys.Send(string keys);SendKeys.SendWa ...
- 如何用javascript获取和设置css3属性
==================获取======================== 我想到的第一个思路 var test = document.getElementById('test'); c ...
- WPF 窗口句柄获取和设置
原文:WPF 窗口句柄获取和设置 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/BYH371256/article/details/83347163 ...
随机推荐
- mooctest项目总结 【转载】
原文链接 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3 ...
- Scott-Knott test 配置与使用
安装最新版本的 R R安装镜像 Download R 3.3.0 for Windows (62 megabytes, 32/64 bit) 理由 Scott-Knott 包由 R 3.2.5 编译的 ...
- Java 学习的几个基础实验(Learn by doing)
0 引子 不少情况下,学生连开发环境都搭建不好,有了实验楼,这个问题基本就解决了. 实验楼是国内首家IT在线实训平台,拥有最丰富的计算机在线实验课,而且全部免费.创业团队对师生的服务非常贴心细致. 1 ...
- pycharm光标变成黑框,恢复成竖线
pycharm光标变成黑框,如下图所示 解决办法: 按外接键盘上的Insert键,即可恢复.
- 修改windows远程默认端口
修改windows远程默认端口 windows端口修改rdp 1 远程服务器运行窗口调出注册表编辑器 注册表编辑器regeidt 2 修改两个注册表 1,在注册表HKEY_LOCAL_MACHINE\ ...
- 设计模式《JAVA与模式》之备忘录模式
在阎宏博士的<JAVA与模式>一书中开头是这样描述备忘录(Memento)模式的: 备忘录模式又叫做快照模式(Snapshot Pattern)或Token模式,是对象的行为模式. 备忘录 ...
- js获取当前页面相关信息
1. 获取整个url: console.log(window.location.href) http://localhost:8082/Index.html?name=tom 2. 获取域名加端口号 ...
- Python小白学习之路(二十四)—【装饰器】
装饰器 一.装饰器的本质 装饰器的本质就是函数,功能就是为其他函数添加附加功能. 利用装饰器给其他函数添加附加功能时的原则: 1.不能修改被修饰函数的源代码 2.不能修改被修饰函数的调用 ...
- Spring集成Solr搜索引擎
1.导入jar包<dependency><groupId>org.apache.solr</groupId><artifactId>solr-solrj ...
- Celery启动Django项目:Client sent AUTH, but no password is set 错误处理
celery -A CeleryTest worker -l info [2017-02-22 07:26:52,666: ERROR/MainProcess] consumer: Cannot co ...