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

      

  • 相关阅读:
    Kibana
    Filebeat使用
    leetcode刷题笔记七十三题 矩阵置零
    leetcode刷题笔记七十二题 编辑距离
    leetcode刷题笔记七十一题 简化路径
    leetcode刷题笔记七十题 爬楼梯
    leetcode刷题笔记六十九题 X的平方根
    python 冒泡算法
    hive 函数
    Task07:类、对象与魔法方法(3天)
  • 原文地址:https://www.cnblogs.com/xiaowie/p/8624327.html
Copyright © 2011-2022 走看看