取控件句柄

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;
using System.Diagnostics;

namespace WindowsFormsApplication16
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        p rivate void button1_Click(object sender, EventArgs e)
        {
            //IntPtr hwnd= Process.GetProcessById().MainWindowHandle;
            String str1 = null;
            str1 += "button1句柄:";
            str1+=button1.Handle.ToString();
            //str1 += "\r\n";
            str1 += Environment.NewLine;

            str1 += "checkbox1句柄:";
            str1 += checkBox1.Handle.ToString();
            //str1 += "\r\n";
            str1 += Environment.NewLine;

            str1 += "label1句柄:";
            str1 += label1.Handle.ToString();
            //str1 += "\r\n";
            str1 += Environment.NewLine;

            str1 += "radioButton1句柄:";
            str1 += radioButton1.Handle.ToString();
            //str1 += "\r\n";
            str1 += Environment.NewLine;

 

            textBox1.Text = str1;
        }


    }
}
 

源代码下载

posted @ 2010-02-15 12:32  猪悟能  阅读(272)  评论(0编辑  收藏  举报