惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Hugging Face - Blog
Hugging Face - Blog
量子位
H
Help Net Security
Microsoft Azure Blog
Microsoft Azure Blog
MongoDB | Blog
MongoDB | Blog
小众软件
小众软件
爱范儿
爱范儿
博客园 - 【当耐特】
Vercel News
Vercel News
S
SegmentFault 最新的问题
M
MIT News - Artificial intelligence
F
Fortinet All Blogs
Apple Machine Learning Research
Apple Machine Learning Research
GbyAI
GbyAI
博客园 - 叶小钗
博客园_首页
V
Visual Studio Blog
宝玉的分享
宝玉的分享
B
Blog
MyScale Blog
MyScale Blog
C
Check Point Blog
博客园 - 三生石上(FineUI控件)
L
LangChain Blog
V
V2EX

博客园 - 云梦鸿

Winform界面显示的“语言”切换 Linux使用笔记 QT 练习笔记 QT 读写配置文件(*.INI) ubuntu 配置网口静态IP C++ 读写文件 C#编写Windows服务 C#代码计算农历(日期、节气、节日) 中标麒麟,使用笔记 关于无密码访问 Windows7/10 的远程桌面/共享 颜色转换:HSB颜色 与 RGB颜色 QT 信号(槽)绑定的使用_connect QT 给控件(Label)设置显示图片 QT 打包Windows应用程序(*.exe) C#程序执行Python脚本 C#监控U盘插拔 C# AnimateWindow 设置窗体动画 C# 创建音频WAVE文件头信息(*.wav) VS2019错误:CS8370 的处理方法
C# GetWindowRect 获取窗体在屏幕中的位置信息
云梦鸿 · 2020-12-24 · via 博客园 - 云梦鸿

利用Win332的API:

     bool GetWindowRect(IntPtr hWnd, ref RECT_INFO lpRect);

  获取指定窗体控件,在屏幕内地位置信息。

using System;
using System.Runtime.InteropServices;

namespace StudySln
{

    public class Win32API
    {

        /// <summary>
        /// 获取指定窗口(或控件)在屏幕中的位置信息 (左边界,上边界,右边界,下边界)
        /// </summary>
        /// <param name="hWnd"></param>
        /// <param name="lpRect"></param>
        /// <returns></returns>
        [DllImport("user32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        public extern static bool GetWindowRect(IntPtr hWnd, ref RECT_INFO lpRect);

    }


    /// <summary>
    /// 矩形范围信息(结构体)
    /// </summary>
    [StructLayout(LayoutKind.Sequential)]
    public struct RECT_INFO
    {
        /// <summary>
        /// 当前矩形范围的最左边界
        /// </summary>
        public int Left;
        /// <summary>
        /// 当前矩形的最上边界
        /// </summary>
        public int Top;
        /// <summary>
        /// 当前矩形的最右边界
        /// </summary>
        public int Right;
        /// <summary>
        /// 当前矩形的最下边界
        /// </summary>
        public int Bottom;
    }
    
}

hWnd:窗口句柄,也可以传递一个控件的Handle值。

lpRect:指向一个RECT结构的指针,该结构接收窗口的左上角和右下角的屏幕坐标。