code:

namespace LOLMM
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Topmost = true;
Loaded += new RoutedEventHandler(MainWindow_Loaded);
t.Interval = TimeSpan.FromMilliseconds(300);
t.Tick += new EventHandler(t_Tick); }
DispatcherTimer t = new DispatcherTimer(); void t_Tick(object sender, EventArgs e)
{
TopMostWindow.SetTopomost(new WindowInteropHelper(this).Handle);
} void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
TopMostWindow.SetTopomost(new WindowInteropHelper(this).Handle);
t.Start();
} }
}

  

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices; namespace LOLMM
{
public class TopMostWindow
{
  public const int HWND_TOP = 0;
  public const int HWND_BOTTOM = 1;
  public const int HWND_TOPMOST = -1;
  public const int HWND_NOTOPMOST = -2;   [DllImport("user32.dll")]
  public static extern IntPtr SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, uint wFlags);   [DllImport("user32.dll")]  
  public static extern bool GetWindowRect(IntPtr hWnd, out WindowRect lpRect);   /// <summary>
  /// 设置窗体为TopMost
  /// </summary>
  /// <param name="hWnd"></param>
  public static void SetTopomost(IntPtr hWnd)
  {
    WindowRect rect = new WindowRect();
    GetWindowRect(hWnd, out rect);
    SetWindowPos(hWnd, (IntPtr)HWND_TOPMOST, rect.Left, rect.Top, rect.Right - rect.Left, rect.Bottom - rect.Top, 0);
  }
} public struct WindowRect
{
  public int Left;
  public int Top;
  public int Right;
  public int Bottom;
} }
//调用方式:
//将此窗体设置为Topmost
//TopMostWindow.SetTopomost(new WindowInteropHelper(this).Handle);

  

C# 设置最顶层窗口。TopMostWindow的更多相关文章

  1. Android 实现顶层窗口、浮动窗口(附Demo)

    做过Window程序开发的朋友应该都知道,我们要把程序窗口置顶很简单,只要设置一些窗口属性即可.但是到了Android,你无法简单设置一个属性,就让Android的Activity置顶.因为只要有新的 ...

  2. Android添加系统级顶层窗口 和 WindowManager添加view的动画问题

    当Dialog有编辑框时如果选择会弹菜单窗口就不要用 Context applicationContext = mainActivity.getApplicationContext(); AlertD ...

  3. c# winform 设置winform进入窗口后在文本框里的默认焦点

    c# winform 设置winform进入窗口后在文本框里的默认焦点 进入窗口后默认聚焦到某个文本框,两种方法: ①设置tabindex 把该文本框属性里的tabIndex设为0,焦点就默认在这个文 ...

  4. 使用API函数EnumWindows()枚举顶层窗口

      http://simpleease.blog.163.com/blog/static/1596085820052770290/ 要枚举Windows当前所有打开的顶层窗口,可使用Windows A ...

  5. WPF 学习笔记-设置属性使窗口不可改变大小

    原文:WPF 学习笔记-设置属性使窗口不可改变大小 调整Windows下的ResizeMode属性: ResizeMode = NoResize Resize属性是控制Windows是否可以改变大小, ...

  6. Win7系统(台式机)设置系统的窗口背景色(豆沙绿色)

    Win7系统(台式机)设置系统的窗口背景色(豆沙绿色) 1,桌面->右键->个性化->窗口颜色->高级外观设置->项目选择(窗口).颜色1(L)选择(其它)将色调改为:8 ...

  7. [转]C# 安装时弹出设置服务登录窗口

    本文转自:http://blog.csdn.net/prince_jun/article/details/38435887 安装服务时系统不要弹出设置服务登录窗口:在程序中将serviceProces ...

  8. css - 所有的a标签设置为新窗口打开

    前言 由于工作的需要,需要把某个页面下的所有a标签都设置为新开新窗口,即:<a href="XXX">增加target:<a href="XXX&quo ...

  9. C# 安装WindowsService时弹出设置服务登录窗口的解决方案

    使用SignalR实现消息推送,页面实时刷新,使用WindowsService作为SignalR的宿主,也就是作为一个消息服务器,在使用cmd命令安装的时候弹出设置服务登录的窗口,解决此问题的具体操作 ...

随机推荐

  1. python+selenium+PhantomJS爬取网页动态加载内容

    一般我们使用python的第三方库requests及框架scrapy来爬取网上的资源,但是设计javascript渲染的页面却不能抓取,此时,我们使用web自动化测试化工具Selenium+无界面浏览 ...

  2. tsung HTTP协议统计报告分析

    tsung HTTP协议统计报告分析 by:授客 QQ:1033553122 1.   Main Static l  higest 10sec mean: 基于每10s的统计,最大耗时 l  lowe ...

  3. Android为TV端助力 SharedPreferences 轻量级存储!

    首先在当前进程也就是当前的项目里面进行存储 SharedPreferences.Editor editor = mContext.getSharedPreferences("tvplay&q ...

  4. git 入门教程之github 教程

    github 教程 github 是一个基于 git 的代码托管平台,是平时工作学习的好帮手,学会如何用好 github 网站能够帮助我们更好分享代码或者与其他开发人员合作. 注册 github 账号 ...

  5. VMware虚拟机CentOS7网络通信与无线上网

    实现主机和虚拟机网络通信 1.虚拟机设置 VMware界面最上面,选择[虚拟机]->[设置]:将网络连接改为"桥接模式",如下图所示: 2.CentOS7网络设置 自动获取I ...

  6. SQL中触发器的使用

    创建触发器 是特殊的存储过程,自动执行,一般不要有返回值 类型: 1.后触发器 (AFTER,FOR)先执行对应语句,后执行触发器中的语句 2.前触发器  并没有真正的执行触发语句(insert,up ...

  7. SQL server 导出平面文件时出错: The code page on Destination - 3_txt.Inputs[Flat File Destination Input].Columns[UserId] is 936 and is required to be 1252.

    我在导出平面文件时:Error 0xc00470d4: Data Flow Task 1: The code page on Destination - 3_txt.Inputs[Flat File ...

  8. a标签下载

    <a href="存在问题.docx" download style="color:red;font-size:20px;cursor:pointer;float: ...

  9. c/c++ 多态的实现原理分析

    多态的实现原理分析 当类里有一个函数被声明成虚函数后,创建这个类的对象的时候,就会自动加入一个__vfptr的指针, __vfptr维护虚函数列表.如果有三个虚函数,则__vfptr指向的是第一个虚函 ...

  10. 用好lua+unity,让性能飞起来——lua与c#交互篇

    前言 在看了uwa之前发布的<Unity项目常见Lua解决方案性能比较>,决定动手写一篇关于lua+unity方案的性能优化文. 整合lua是目前最强大的unity热更新方案,毕竟这是唯一 ...