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

    原文地址:http://www.cnblogs.com/08shiyan/archive/2011/04/14/2015758.html

    /**********************
    
     * 课题:将窗体中鼠标所在控件名显示在窗体标题上
     * 作者: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;
      }
      }
    }
  • 相关阅读:
    6、查看历史记录
    A Tour of Go Range
    Go Slices: usage and internals
    A Tour of Go Nil slices
    A Tour of Go Making slices
    A Tour of Go Slicing slices
    A Tour of Go Slices
    A Tour of Go Arrays
    A Tour of Go The new function
    A Tour of Go Struct Literals
  • 原文地址:https://www.cnblogs.com/helloEveryBody/p/6149518.html
Copyright © 2011-2022 走看看