一、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++;
}

最新文章

  1. 记住密码超简单实现(C#)
  2. [Reomting Debug] 巧用VS 的remote debug 功能远程调试程序 经验分享.
  3. SQL Server with(nolock)详解
  4. Koala编译less
  5. 如何使用validate.js进行动态添加和移除表单验证信息
  6. 记录IOS入门的过程
  7. 【H5开发基础】移动端1像素边框问题的解决方案
  8. 为什么选择MongoDB?
  9. php fsockopen
  10. 使用.NET Core快速开发一个较正规的命令行应用程序
  11. Oracle外部表与SQLLDR
  12. 03_ if 练习 _ little2big
  13. SqlServer 行转一列逗号隔开
  14. oracle优化技巧及实例(总结)
  15. matchmove流程中修改Maya相机数据的脚本
  16. 解决sublime3不能编辑插件default settings的问题
  17. Liferay-Activiti 功能介绍 (新版Liferay7基本特性)
  18. LTE:eMBMS架构
  19. [转]如何取得当前正在执行的shell脚本的绝对路径?
  20. 1025 PAT Ranking (25)(25 point(s))

热门文章

  1. Mac系统登录不进系统解决办法
  2. 工作随笔——获取当前Java程序PID
  3. C# 移动及限制移动距离
  4. python--Websocket实现, 加密 sha1,base64
  5. 06_python_小数据池/ is == /编码
  6. Windows+MyEclipse+MySQL【连接数据库报错caching_sha2_password】
  7. 写一个MySql存储过程实现房贷等额本息还款计算(另外附javascript代码)
  8. 第一章-Javac编译器介绍
  9. PHP-引入文件(include)后,页面错位,不居中解决办法
  10. Vue源码翻译之组件初始化。