C# 设置最顶层窗口。TopMostWindow
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的更多相关文章
- Android 实现顶层窗口、浮动窗口(附Demo)
做过Window程序开发的朋友应该都知道,我们要把程序窗口置顶很简单,只要设置一些窗口属性即可.但是到了Android,你无法简单设置一个属性,就让Android的Activity置顶.因为只要有新的 ...
- Android添加系统级顶层窗口 和 WindowManager添加view的动画问题
当Dialog有编辑框时如果选择会弹菜单窗口就不要用 Context applicationContext = mainActivity.getApplicationContext(); AlertD ...
- c# winform 设置winform进入窗口后在文本框里的默认焦点
c# winform 设置winform进入窗口后在文本框里的默认焦点 进入窗口后默认聚焦到某个文本框,两种方法: ①设置tabindex 把该文本框属性里的tabIndex设为0,焦点就默认在这个文 ...
- 使用API函数EnumWindows()枚举顶层窗口
http://simpleease.blog.163.com/blog/static/1596085820052770290/ 要枚举Windows当前所有打开的顶层窗口,可使用Windows A ...
- WPF 学习笔记-设置属性使窗口不可改变大小
原文:WPF 学习笔记-设置属性使窗口不可改变大小 调整Windows下的ResizeMode属性: ResizeMode = NoResize Resize属性是控制Windows是否可以改变大小, ...
- Win7系统(台式机)设置系统的窗口背景色(豆沙绿色)
Win7系统(台式机)设置系统的窗口背景色(豆沙绿色) 1,桌面->右键->个性化->窗口颜色->高级外观设置->项目选择(窗口).颜色1(L)选择(其它)将色调改为:8 ...
- [转]C# 安装时弹出设置服务登录窗口
本文转自:http://blog.csdn.net/prince_jun/article/details/38435887 安装服务时系统不要弹出设置服务登录窗口:在程序中将serviceProces ...
- css - 所有的a标签设置为新窗口打开
前言 由于工作的需要,需要把某个页面下的所有a标签都设置为新开新窗口,即:<a href="XXX">增加target:<a href="XXX&quo ...
- C# 安装WindowsService时弹出设置服务登录窗口的解决方案
使用SignalR实现消息推送,页面实时刷新,使用WindowsService作为SignalR的宿主,也就是作为一个消息服务器,在使用cmd命令安装的时候弹出设置服务登录的窗口,解决此问题的具体操作 ...
随机推荐
- Deep Learning - 3 改进神经网络的学习方式
反向传播算法是大多数神经网络的基础,我们应该多花点时间掌握它. 还有一些技术能够帮助我们改进反向传播算法,从而改进神经网络的学习方式,包括: 选取更好的代价函数 正则化方法 初始化权重的方法 如何选择 ...
- NoHttp封装--08 用一个实体类接收所有接口数据
1.用户信息获取--bean实体类形式返回数据 ①服务器端: 代码: protected void onHandler(HttpServletRequest request, HttpServletR ...
- .net 前端gb2312编码,后台获取参数乱码(因为表单提交的时候是utf-8编码 则在后台读取参数时会出现乱码)
在表单中设置编码 ' accept-charset="utf-8" '即可: <form id="login_submit" action=" ...
- Scrapy 为每一个Spider设置自己的Pipeline
settings中的ITEM_PIPELINES 通常我们需要把数据存在数据库中,一般通过scrapy的pipelines管道机制来实现.做法是,先在pipelines.py模块中编写Pipeline ...
- DBA思考系列——学会拒绝不合理的需求
DBA思考系列--学会拒绝不合理的需求 一直以来,个性都比较随意,一般很少拒绝开发人员的一些需求(有点老好人的感觉). 这点一直被老大诟病,也一直在反省!最近又有一件事情,让我觉得:应该学会拒绝不 ...
- Mysql----修改MySQL5.7的root的密码
在开始服务的情况之下 进入mysql 更改密码:update mysql.user set authentication_string=password('新的密码') where user='r ...
- CentOS 6.5 安装mysql 过程记录
下载的时候一定选对应的版本, el6 还是el7 或者其他版本,不然会出现意向不到的惊喜 比如:我刚开始的时候下载的 el7 版本的 mysql , 然后安装的时候 就会出现: libc.so.(GL ...
- DubboAdmin部署
1.软件下载 部署管理后台和监控中心需要以下软件 opensesame 下载地址:https://github.com/alibaba/opensesame Dubbo源码下载 https://g ...
- 新安装 Ubuntu 系统设置root用户密码!谨此纪念自己踩过的坑!
Ubuntu 在安装过程中创建的用户为普通用户,而root 用户密码该如何设置呢? 执行以下命令即可: sudo passwd root 提示你输入普通用户密码,然后设置root用户的密码!这样,就更 ...
- #007 C语言大作业学生管理系统第四天
第四天还差恢复已删除学生功能 对于我来说,已经开始很复杂了. 小细节太重要了,边写边出错 1 #include<stdio.h> #include<stdlib.h> #inc ...