zoukankan      html  css  js  c++  java
  • GroupBox 分组框控件

    GroupBox 控件是由System.Windows.Forms.GroupBox类提供的,作用是为其他控件提供可识别的分组

     

    可在同一页面,实现多个单选的RadioButton

     

    通常,使用分组框按功能细分窗体,例如,一个学生在璇姐班级和系别时,为了细分窗体,可用两个GroupBox控件来设置,用Text属性来达到分组提示的目的

    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 GroupBox_分组框控件
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                this.Text = "GroupBox 分组控件";
                
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                string mystr = "";   //定义一个字符串来接受循环遍历后的结果
                foreach (Control outcon in groupBox1.Controls)   //循环遍历control(控件) 在分组框控件中
                {
                    if (outcon is RadioButton)   //判断 是不是radiobutton 控件(有可能还要加checkbutton)
                    {
                        if (((RadioButton)outcon).Checked)   //判断这个radiobutton是否被选中(checked)前面的(radiobutton)是将outcon这个控件强制转换为radiobutton
                        {
                            mystr = "您的种族是:" + outcon.Text;   //用定义好的变量来接收控件上的txet
                        }
                    }
                }
                foreach (Control outcontrol in groupBox2.Controls)
                {
    
                    if (outcontrol is RadioButton)
                    {
                        if (((RadioButton)outcontrol).Checked)
                        {
                            mystr="您的所属:"+outcontrol.Text+"	"+mystr;
                        }
                    }
                }
                MessageBox.Show(mystr);
            }
        }
    }
    

      

  • 相关阅读:
    apache与tomcat负载集群的3种方法
    JFinal 源码分析 [DB+ActiveRecord]
    通过PowerShell获取TCP响应(类Telnet)
    Linux 硬盘分区、分区、删除分区、格式化、挂载、卸载
    常用EXE文件反编译工具
    Shell采集系统cpu 内存 磁盘 网络信息
    MyEclipse运行很慢的原因
    Java令牌生成器
    Shell 编程基础之基本语法结构汇总
    Shell 编程基础之注意技巧
  • 原文地址:https://www.cnblogs.com/xiaowie/p/8624327.html
Copyright © 2011-2022 走看看