日期:2014-05-19  浏览次数:20943 次

请问如何通过Graphics对象获取它所属的Control呢?
多谢!

------解决方案--------------------
//参考如下代码
using System.Runtime.InteropServices;

[DllImport( "user32.dll ")]
public static extern IntPtr WindowFromDC(IntPtr hDC);

private void button1_Click(object sender, EventArgs e)
{
Graphics vGraphics = Graphics.FromHwnd(Handle);
Control vControl = Control.FromHandle(WindowFromDC(vGraphics.GetHdc()));
if (vControl != null) MessageBox.Show(vControl.Name);
}