zoukankan      html  css  js  c++  java
  • C# WinForm中 获得当前鼠标所在控件 或 将窗体中鼠标所在控件名显示在窗体标题上

    转:/**********************

     * 课题:将窗体中鼠标所在控件名显示在窗体标题上
     * 作者:ZAXX
     * QQ : 94027486
     * 本课题可简单扩展:获取屏幕上鼠标所在位置的窗口句柄与类名
     **********************/
    using System;
    using System.Drawing;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    namespace Zaxx
    {
      public partial class MouseOnControl: Form
      {
      [DllImport("User32.dll")]
      private static extern IntPtr WindowFromPoint(Point p);

      Timer timer;

      public MouseOnControl()
      {
      InitializeComponent();
      timer = new Timer();
      timer.Interval = 200;
      timer.Enabled = true;
      timer.Tick += new EventHandler(timer_Tick);
      }

      void timer_Tick(object sender, EventArgs e)
      {
      Point p = Cursor.Position;
      IntPtr h = WindowFromPoint(p);
      foreach (Control con in this.Controls)
      if (con.Handle == h)
      this.Text = con.Name;
      }
      }
    }



    返回导读目录,阅读更多随笔



    分割线,以下为博客签名:

    软件臭虫情未了
    • 编码一分钟
    • 测试十年功


    随笔如有错误或不恰当之处、为希望不误导他人,望大侠们给予批评指正。

  • 相关阅读:
    视频:JDBCRDD源码及自定义JDBCRDD的分区策略
    聊聊spark-submit的几个有用选项
    线性求第k大
    汇编基础 第一章_总线
    长度不超过n的连续最大和___优先队列
    ISAP
    次小生成树
    k短路
    求出欧拉回路,欧拉路径
    拓扑排序bfs_dfs
  • 原文地址:https://www.cnblogs.com/08shiyan/p/2015758.html
Copyright © 2011-2022 走看看