• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
wjshan0808

Learn from yesterday, Live for today, For a better tomorrow.
 ————wjshan0808

博客园    首页    新随笔    联系   管理    订阅  订阅

遍历form中的所有空间并找到选中的radiobutton

源文件: 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);
        }

    }
}

 


posted @ 2013-06-23 22:54  wjshan0808  阅读(459)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3