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+"\t"+mystr;
                    }
                }
            }
            MessageBox.Show(mystr);
        }
    }
}

  

转载于:https://www.cnblogs.com/xiaowie/p/8624327.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
namespace comput { /// <summary> /// 这是一个计算器的简单实现。 /// </summary> public class Form1 : System.Windows.Forms.Form { #region 控件声明 private System.Windows.Forms.TextBox txtShow; private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.Button btn_rev; private System.Windows.Forms.Button btn_dot; private System.Windows.Forms.Button btn_add; private System.Windows.Forms.Button btn_equ; private System.Windows.Forms.Button btn_sign; private System.Windows.Forms.Button btn_sub; private System.Windows.Forms.Button btn_mul; private System.Windows.Forms.Button btn_0; private System.Windows.Forms.Button btn_3; private System.Windows.Forms.Button btn_2; private System.Windows.Forms.Button btn_1; private System.Windows.Forms.Button btn_6; private System.Windows.Forms.Button btn_5; private System.Windows.Forms.Button btn_4; private System.Windows.Forms.Button btn_sqrt; private System.Windows.Forms.Button btn_div; private System.Windows.Forms.Button btn_7; private System.Windows.Forms.Button btn_8; private System.Windows.Forms.Button btn_9; private System.Windows.Forms.MainMenu mainMenu1; private System.Windows.Forms.MenuItem menuItem1; private System.Windows.Forms.Button btn_sqr; private System.Windows.Forms.MenuItem menuItem2; private System.Windows.Forms.MenuItem menuItem3; private System.Windows.Forms.MenuItem menuItem4; private System.Windows.Forms.MenuItem menuItem5; private System.Windows.Forms.MenuItem menuItem6; private System.Windows.Forms.Button c; private System.Windows.Forms.Button ce; private System.Windows.Forms.MenuItem menuItem8; private System.Windows.Forms.MenuItem menuItem9; private System.Windows.Forms.MenuItem menuItem10; /// <summary> /// 必需的设计器变量。 /// </summary>
namespace TextReader { partial class TextReader { /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// 清理所有正在使用的资源。 /// </summary> /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows 窗体设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要 /// 使用代码编辑器修改此方法的内容。 /// </summary> private void InitializeComponent() { this.txtContent = new System.Windows.Forms.TextBox(); this.groupBox1 = new System.Windows.Forms.GroupBox(); this.label1 = new System.Windows.Forms.Label(); this.btnRead = new System.Windows.Forms.Button(); this.btnWrite = new System.Windows.Forms.Button(); this.txtFilePath = new System.Windows.Forms.TextBox(); this.groupBox1.SuspendLayout(); this.SuspendLayout(); // // txtContent // this.txtContent.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.txtContent.Location = new System.Drawing.Point(12, 84); this.txtContent.Multiline = true; this.txtContent.Name = "txtContent"; this.txtContent.Size = new System.Drawing.Size(535, 285); this.txtContent.TabIndex = 0; // // groupBox1 // this.groupBox1.Controls.Add(this.label1); this.groupBox1.Controls.Add(this.btnRead); this.groupBox1.Controls.Add(this.btnWrite); this.groupBox1.Controls.Add(this.txtFilePath); this.groupBox1.Location = new System.Drawing.Point(12, 12); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(536, 49); this.groupBox1.TabIndex = 5; this.groupBox1.TabStop = false; // // label1 // this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.label1.AutoSize = true; this.label1.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.label1.Location = new System.Drawing.Point(8, 19); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(72, 16); this.label1.TabIndex = 8; this.label1.Text = "文件位置"; // // btnRead // this.btnRead.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.btnRead.Location = new System.Drawing.Point(459, 18); this.btnRead.Name = "btnRead"; this.btnRead.Size = new System.Drawing.Size(60, 23); this.btnRead.TabIndex = 7; this.btnRead.Text = "读取"; this.btnRead.UseVisualStyleBackColor = true; this.btnRead.Click += new System.EventHandler(this.btnRead_Click); // // btnWrite // this.btnWrite.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.btnWrite.Location = new System.Drawing.Point(393, 18); this.btnWrite.Name = "btnWrite"; this.btnWrite.Size = new System.Drawing.Size(60, 23); this.btnWrite.TabIndex = 6; this.btnWrite.Text = "写入"; this.btnWrite.UseVisualStyleBackColor = true; this.btnWrite.Click += new System.EventHandler(this.btnWrite_Click); // // txtFilePath // this.txtFilePath.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.txtFilePath.Location = new System.Drawing.Point(87, 18); this.txtFilePath.Name = "txtFilePath"; this.txtFilePath.Size = new System.Drawing.Size(296, 21); this.txtFilePath.TabIndex = 5; // // TextReader // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(559, 381); this.Controls.Add(this.groupBox1); this.Controls.Add(this.txtContent); this.Name = "TextReader"; this.Text = "TextReader"; this.groupBox1.ResumeLayout(false); this.groupBox1.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); } #endregion private System.Windows.Forms.TextBox txtContent; private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.Label label1; private System.Windows.Forms.Button btnRead; private System.Windows.Forms.Button btnWrite; private System.Windows.Forms.TextBox txtFilePath; } }

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值