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);
            }
        }
    }
    

      

  • 相关阅读:
    OCP-1Z0-051-V9.02-26题
    谨慎使用A2W等字符转换宏
    MySQL 递归查询 当前节点及子节点
    std count_if用法
    OCP-1Z0-053-V12.02-660题
    OCP-1Z0-053-V12.02-667题
    OCP-1Z0-053-V12.02-676题
    OCP-1Z0-051-V9.02-159题
    手工不完全恢复(非归档模式下,日志被覆盖)
    手工完全恢复(非归档模式下,日志没有被覆盖)
  • 原文地址:https://www.cnblogs.com/xiaowie/p/8624327.html
Copyright © 2011-2022 走看看