All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
详谈基于JSON的高级AJAX开发技术_.net资料_编程技术
delphi坐标系统使用方法详解
用PHP连接Oracle数据库_php资料_编程技术
delphi常用的几个路径函数
如何构造一个C#语言的爬虫程序_[Asp.Net教程]
ASP.NET,2.0服务器控件开发之复杂属性_[Asp.Net教程]
ASP.NET,2.0,ObjectDataSource控件_[Asp.Net教程]
SQL Server单引号两种处理技巧_[SQL Server教程]
php函数substr实现asp中left和right功能_php资料_编程技术
理解学习PHP编码规范之注释和文件结构_php资料_编程技术
Reading number is top 10 pictures
教你做读书笔记
The money of more than 100 countries and regions15
Female model behind the bitterness, often being overcharged1
这年头,找个靠谱的妹子太难了
这才是真正的人体艺术1
Seductive beauty of crime1
Ashlynn Brooke show proud chest measurement3
传销的好处
Gang rape
9.3阅兵全景图6-常规导弹梯队和核导弹梯队
Download software ranking
1400篇各类破解文章
Unix video tutorial8
Boxer's Top ten classic battle8
Sora aoi, the nurse, uniform ,nursing assistant
少妇苏霞全本
Boxer's Top ten classic battle10
VC++6.0简体中文版
linux安装大全
WebService在.NET中的实战应用教学视频 → 第5集
塘西风月痕
qq published in(发表于) 2014/7/11 9:15:57 Edit(编辑)
C#中CheckBox控件应用实例

C#中CheckBox控件应用实例

C#中CheckBox控件应用实例

CheckBox控件

1.功能

CheckBox控件指定某个特定条件是处于打开状态还是处于关闭状态,它常用于为用户提供“是/否”或“真/假”选项。图1为CheckBox控件。



图1 CheckBox控件

2.属性

CheckBox控件常用属性及说明如表1所示。



表1 CheckBox控件常用属性及说明

下面详细介绍Checked属性,该属性用于指定复选框是否处于选中状态。

语法:

public bool Checked { get; set; }

属性值:如果CheckBox处于选定状态,则为True;否则为False。默认值为False。

注意:如果将ThreeState属性设置为True,则Checked属性将为Checked或Indeterminate CheckState返回True。

示例

使用Checked属性判断复选框是否选中

本示例使用Checked属性判断复选框是否选中,并给出提示信息。示例运行结果如图2所示。



图2 使用Checked属性判断复选框是否选中

程序主要代码如下:

if (this.checkBox1.Checked == False && this.checkBox2.Checked ==False && checkBox3.Checked == False)

{

MessageBox.Show("至少选一项爱好");

return;

}

if (radioButton1.Checked == False && radioButton2.Checked == False)

{

MessageBox.Show("请选择性别");

return;

}

完整程序代码如下:

★★★★★主程序文件完整程序代码★★★★★

using System;

using System.Collections.Generic;

using System.Windows.Forms;

namespace _8_10

{

static class Program

{

///



/// 应用程序的主入口点。

///


[STAThread]

static void Main()

{

Application.EnableVisualStyles();

Application.SetCompatibleTextRenderingDefault(false);

Application.Run(new frmCheckBox());

}

}

}

★★★★★frmCheckBox窗体设计文件完整程序代码★★★★★

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

namespace _8_10

{

public partial class frmCheckBox : Form

{

public frmCheckBox()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

if (this.checkBox1.Checked == false && this.checkBox2.Checked ==false && checkBox3.Checked == false)

{

MessageBox.Show("至少选一项爱好");

return;

}

if (radioButton1.Checked == false && radioButton2.Checked == false)

{

MessageBox.Show("请选择性别");

return;

}

}

private void button2_Click(object sender, EventArgs e)

{

Application.Exit();

}

private void checkBox1_CheckedChanged(object sender, EventArgs e)

{

}

private void checkBox2_CheckedChanged(object sender, EventArgs e)

{

}

private void checkBox3_CheckedChanged(object sender, EventArgs e)

{

}

private void button3_Click(object sender, EventArgs e)

{

}

private void button4_Click(object sender, EventArgs e)

{

}

private void checkedListBox1_Click(object sender, EventArgs e)

{

}

private void frmCheckBox_Load(object sender, EventArgs e)

{

}

}

}

★★★★★frmCheckBox窗体代码文件完整程序代码★★★★★

namespace _8_10

{

partial class frmCheckBox

{

///

/// 必需的设计器变量。

///


private System.ComponentModel.IContainer components = null;

///

/// 清理所有正在使用的资源。

///


/// 如果应释放托管资源,为 true;否则为 false。

protected override void Dispose(bool disposing)

{

if (disposing && (components != null))

{

components.Dispose();

}

base.Dispose(disposing);


添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.