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

      

  • 相关阅读:
    简明Python3教程 12.问题解决
    简明Python3教程 11.数据结构
    【SPOJ 694】Distinct Substrings
    【codeforces Manthan, Codefest 17 C】Helga Hufflepuff's Cup
    【CF Manthan, Codefest 17 B】Marvolo Gaunt's Ring
    【CF Manthan, Codefest 17 A】Tom Riddle's Diary
    【SPOJ 220】 PHRASES
    【POJ 3261】Milk Patterns
    【POJ 3294】Life Forms
    【POJ 1226】Substrings
  • 原文地址:https://www.cnblogs.com/xiaowie/p/8624327.html
Copyright © 2011-2022 走看看