一、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的使用方法的更多相关文章

  1. WPF获取和设置鼠标位置与progressbar的使用方法

    一.WPF 中获取和设置鼠标位置 方法一:WPF方法 Point p = Mouse.GetPosition(e.Source as FrameworkElement); Point p = (e.S ...

  2. javascript获取以及设置光标位置

    一. 获取光标位置: // 获取光标位置 function getCursortPosition (textDom) { var cursorPos = 0; if (document.selecti ...

  3. OpenCV获取与设置像素点的值的几个方法

    Title: OpenCV OpenCV像素值的获取与设置 Fn 1 : 使用 Mat 中对矩阵元素的地址定位的知识 (参考博文:OpenCV中对Mat里面depth,dims,channels,st ...

  4. unity获取ugui上鼠标位置

    public class GetMousePos : MonoBehaviour { public Canvas canvas;//画布 private RectTransform rectTrans ...

  5. $(window).scrollTop() 获取当前的鼠标位置 offset.left()指定标签在html中的坐标 offset.top() 指定标签在html中的坐标position() 指定标签相对父(relative)标签的坐标

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. WPF 程序鼠标在窗口之外的时候,控件拿到的鼠标位置在哪里?

    原文:WPF 程序鼠标在窗口之外的时候,控件拿到的鼠标位置在哪里? 在 WPF 程序中,我们有 Mouse.GetPosition(IInputElement relativeTo) 方法可以拿到鼠标 ...

  7. 使用C#模拟键盘输入、鼠标移动和点击、设置光标位置及控制应用程序的显示

    1.模拟键盘输入(SendKeys) 功能:将一个或多个按键消息发送到活动窗口,就如同在键盘上进行输入一样. 语法:SendKeys.Send(string keys);SendKeys.SendWa ...

  8. 如何用javascript获取和设置css3属性

    ==================获取======================== 我想到的第一个思路 var test = document.getElementById('test'); c ...

  9. WPF 窗口句柄获取和设置

    原文:WPF 窗口句柄获取和设置 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/BYH371256/article/details/83347163 ...

随机推荐

  1. 如何实现php手机短信验证功能

    http://www.qdexun.cn/jsp/news/shownews.do?method=GetqtnewsdetailAction&id=1677 下载php源代码 现在网站在建设网 ...

  2. Android GridView 滑动条设置一直显示状态

    模拟GridView控件: <GridView android:id="@+id/picture_grid" android:layout_width="match ...

  3. python--求参赛两队所有可能的比赛组合情况

    朋友遇到一个面试题,让我帮忙实现,题目如下: 红队有A1,B1,C1三名队员,蓝队有A2,B2,C2三名队员,每轮比赛各队出一名队员参加,一名队员只能参加一次比赛,假设A1不会和B2打,B1不会和B2 ...

  4. Centos7 下一键安装JDK和Maven

    JDK 1. 使用yum search java|grep jdk 查看jdk版本 2. 选择版本安装 yum install java-1.7.0-openjdk,如果用1.8的,只用改版本号即可. ...

  5. ASP.Net Core 2.2 MVC入门到基本使用系列 (二)

    本教程会对基本的.Net Core 进行一个大概的且不会太深入的讲解, 在您看完本系列之后, 能基本甚至熟练的使用.Net Core进行Web开发, 感受到.Net Core的魅力. 本教程知识点大体 ...

  6. JQuery Mobile - 自定义图标!

    环境 jquery1.9.1.js jquery mobile 1.4.2版 图标制作 18x18px 底透明的png图标 使用图标,这个过程开始怎么弄都不行,只有个灰色的圆出现,不见图标:或者出现图 ...

  7. 代码审计| HDWiki 漏洞(一)

    i春秋核心白帽:yanzm 0×00 背景 最近拿到一个源码素材于是对这个源码进行分析发现了不少漏洞本篇先将一些漏洞进行分析下一篇再进行GetShell方法的分析期待和师傅们的交流. 0×01 漏洞分 ...

  8. java urlrewrite实现伪静态化

    1.示例 http://www.onlyfun.com/goods/company.jsp?companyId=455326 ==> http://www.onlyfun.com/company ...

  9. css3中那些鲜为人知但又很有用的属性

    概述 这是我在写移动端页面的时候遇到的,css3中鲜为人知但又很有用的属性,记录下来,供以后开发时参考,相信对其他人也有用. tap-highlight-color 在移动端开发中,我们需要在用户轻按 ...

  10. WebDriver高级应用实例(6)

    6.1精确比较网页截图图片 目的:对于核心界面进行截屏,并且使用测试过程中的截图和以前测试过程中的截图进行比较.确认页面是否发生了改变 被测网页的网址: http://www.baidu.com Ja ...