110,477
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication7
{
public partial class Form1 : Form, IMessageFilter
{
public Form1()
{
InitializeComponent();
Application.AddMessageFilter(this);
Panel P1 = new Panel();
P1.Parent = this;
Panel P2 = new Panel();
P2.Parent = P1;
new TextBox().Parent = P2;
}
public bool PreFilterMessage(ref Message m)
{
int WM_LBUTONDOWN = 0x201;
if (m.Msg == WM_LBUTONDOWN)
{
Control C = GetChild(this.Controls);
if (C != null)
MessageBox.Show(C.GetType().Name);
}
return false;
}
Control GetChild(Control.ControlCollection CC)
{
foreach (Control C in CC)
if (C.Bounds.Contains(C.Parent.PointToClient(Control.MousePosition)))
{
Control TC = GetChild(C.Controls);
if (TC == null)
return C;
else
return TC;
}
return null;
}
}
}