源文件: http://pan.baidu.com/share/link?shareid=1481950339&uk=3912660076

参考:http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.aspx

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 FoundTheControl
{
    public partial class FC : Form
    {
        public FC()
        {
            InitializeComponent();
        }

        private void btnGo_Click(object sender, EventArgs e)
        {
            lblResult.Text = "Result->";
            GetCurrentControl();
        }
        public void GetCurrentControl()
        {
            foreach (Form items in Application.OpenForms)
            {
                foreach (Control ct in items.Controls)
                {
                    if (ct.HasChildren)
                    {
                        GetControl(ct);
                    }
                    if (ct is RadioButton)
                    {
                        RadioButton rb = (RadioButton)ct;
                        if (rb.Checked)
                        {
                            ListViewItem lvi = new ListViewItem(rb.Name);
                           
                            lvi.SubItems.Add(rb.Text);
                            lvi.SubItems.Add(rb.GetType().ToString());
                            lstvwResult.Items.Add(lvi);                            
                        }
                    }
                }
            }
        }
        private void GetControl(Control ctls)
        {
            foreach (Control ctl in ctls.Controls)
            {
                if (ctl.HasChildren)
                {
                    GetControl(ctl);
                }
                if (ctl.GetType() == typeof(RadioButton))
                {
                    RadioButton rb = (RadioButton)ctl;

                    if (rb.Checked)
                    {
                        ListViewItem lvi = new ListViewItem(rb.Name);
                        
                        lvi.SubItems.Add(rb.Text);
                        lvi.SubItems.Add(rb.GetType().ToString());
                        lstvwResult.Items.Add(lvi);
                        
                    }
                }
            }
        }

        private void rchtxtOne_LinkClicked(object sender, LinkClickedEventArgs e)
        {
            //e.LinkText = rchtxtOne.Lines[13].ToString() + rchtxtOne.Lines[14].ToString();
            System.Diagnostics.Process.Start("iexplore", e.LinkText);
        }

    }
}

 

相关文章: