原文:WPF 精修篇 调用Win32Api

栗子是 调用WIn32API 让窗口最前

后台代码


  1. [DllImport("user32.dll")]
  2. private static extern bool SetForegroundWindow(IntPtr hWnd);
  3. //
  4. Process process = null;
  5. private void OPenButton_Click(object sender, RoutedEventArgs e)
  6. {
  7. process = new Process();
  8. process.StartInfo.FileName = "iexplore.exe";
  9. process.StartInfo.Arguments = Text_Path.Text;
  10. process.Start();
  11. }
  12. private void TOPButton_Click(object sender, RoutedEventArgs e)
  13. {
  14. if (process != null)
  15. {
  16. var ptr = process.MainWindowHandle;
  17. SetForegroundWindow(ptr);
  18. }
  19. }
  20. private void FlushButton_Click(object sender, RoutedEventArgs e)
  21. {
  22. if (process != null)
  23. {
  24. var ptr = process.MainWindowHandle;
  25. SetForegroundWindow(ptr);
  26. SendKeys.SendWait("{F5}");
  27. }
  28. }

前台


  1. <Grid>
  2. <TextBox x:Name="Text_Path" HorizontalAlignment="Left" Height="25" Margin="0,34,0,0" TextWrapping="Wrap" Text="https://www.baidu.com" VerticalAlignment="Top" Width="251" />
  3. <Button x:Name="OPenButton" Content="打开" HorizontalAlignment="Left" Margin="10,86,0,0" VerticalAlignment="Top" Width="75" Click="OPenButton_Click"/>
  4. <Button x:Name="TOPButton" Content="前台" HorizontalAlignment="Left" Margin="10,123,0,0" VerticalAlignment="Top" Width="75" Click="TOPButton_Click"/>
  5. <Button x:Name="FlushButton" Content="刷新" HorizontalAlignment="Left" Margin="10,160,0,0" VerticalAlignment="Top" Width="75" Click="FlushButton_Click"/>
  6. </Grid>

SendKeys.SendWait("{F5}"); 需要引用System.Windows.Forms.dll

WPF 精修篇 调用Win32Api的更多相关文章

  1. WPF 精修篇 数据触发器

    原文:WPF 精修篇 数据触发器 数据触发器 可以使用Binding 来绑定控件 或者数据源 来触发相关动作 举栗子 <Window.Resources> <Style Target ...

  2. WPF 精修篇 属性触发器

    原文:WPF 精修篇 属性触发器 属性触发器是通过  某个条件触发改变属性 通过无代码实现功能 <Style TargetType="{x:Type Label}"> ...

  3. WPF 精修篇 样式继承

    原文:WPF 精修篇 样式继承 这个 是新知识 样式可以继承 <Style x:Key="TextBlockStyleBase" TargetType="{x:Ty ...

  4. WPF 精修篇 自定义控件

    原文:WPF 精修篇 自定义控件 自定义控件 因为没有办法对界面可视化编辑 所以用来很少 现在实现的是 自定义控件的 自定义属性 和自定义方法 用VS 创建自定义控件后 会自动创建 Themes 文件 ...

  5. WPF 精修篇 用户控件

    原文:WPF 精修篇 用户控件 增加用户控件 数据绑定还是用依赖属性 使用的事件 就委托注册一下 public delegate void ButtonClick(object b,EventArgs ...

  6. WPF 精修篇 DataGrid 筛选

    原文:WPF 精修篇 DataGrid 筛选 DataGrid也可以分组 但是用的地方不多 就没写 筛选还是可以的 比如Datagrid数据量比较大 要做数据筛选 贴码 <DataGrid x: ...

  7. WPF 精修篇 DataGrid 数据源排序

    原文:WPF 精修篇 DataGrid 数据源排序 效果 <DataGrid x:Name="datagrid" ItemsSource="{Binding Ele ...

  8. WPF 精修篇 数据绑定到对象

    原文:WPF 精修篇 数据绑定到对象 数据绑定到对象 首先 我们需要一个对象 public class Preson { private string name; public string Name ...

  9. WPF 精修篇 数据绑定 更新通知

    原文:WPF 精修篇 数据绑定 更新通知 开始更新一点有意思的了 首先 数据绑定  其中之一 Element 绑定 看例子 <Window x:Class="WpfApplicatio ...

随机推荐

  1. Android 自定义水平进度条的圆角进度

    有时项目中需要实现水平圆角进度,如下两种,其实很简单     下面开始看代码,先从主界面布局开始看起: <?xml version="1.0" encoding=" ...

  2. [小程序]微信小程序获取位置展示地图并标注信息

    1.map组件的高度如果想要铺满屏幕,要是使用height:100vh样式2.获取位置要在app.json中标明权限3.先使用wx.getLocation获取自己的位置,然后再回调中使用setData ...

  3. Linux命令——ethtool

    转自:https://www.cnblogs.com/kelamoyujuzhen/p/10116423.html 参考:9 Linux ethtool Examples to Manipulate ...

  4. AWS之EC2搭建WordPress博客

    AWS之搭建WordPress博客 注意:请确定您已经成功完成LAMP架构的搭建; 1.下载并解压WordPress安装包: ①使用wget命令在WordPress官网获取最新安装包: [ec2-us ...

  5. mysql常用配置注意项与sql优化

    建立数据库: 建立数据库时编码字符集采用utf8 排序规则: 后缀"_cs"或者"_ci"意思是区分大小写和不区分大小写(Case Sensitive & ...

  6. 整合SpringTask实现定时任务

    一.框架介绍 SpringTask是Spring自主研发的轻量级定时任务工具,相比于Quartz更加简单方便,且不需要引入其他依赖即可使用. 二.Corn表达式 概述 Cron表达式是一个字符串,包括 ...

  7. 网络yum源配置

    系统环境:CentOS7 [1] 首先备份/etc/yum.repos.d/CentOS-Base.repo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum ...

  8. 【目标检测】YOLO:

    PPT 可以说是讲得相当之清楚了... deepsystems.io 中文翻译: https://zhuanlan.zhihu.com/p/24916786 图解YOLO YOLO核心思想:从R-CN ...

  9. LOJ 数列分块入门系列

    目录 1.区间加+单点查 每个块维护tag,散的暴力改. code: #include<bits/stdc++.h> using namespace std; const int maxn ...

  10. [LeetCode] 658. Find K Closest Elements 寻找K个最近元素

    Given a sorted array, two integers k and x, find the k closest elements to x in the array. The resul ...