范文健康探索娱乐情感热点
投稿投诉
热点动态
科技财经
情感日志
励志美文
娱乐时尚
游戏搞笑
探索旅游
历史星座
健康养生
美丽育儿
范文作文
教案论文
国学影视

WinForm(五)控件和它的成员

  窗体无疑是WinForm的主角,每个窗体都是用一个class来承载,那么窗体的控件,就是类中的私有字段了。每个窗体有三个文件,两个.cs文件,是一个分部类,Designer.cs是自动生成的C#代码,一般是拖拽控件后生成的代码;另一个.cs文件是写业务代码用的;第三个是.resx文件,是资源文源,窗体的图片,图标,以及一些控件的配置信息。
  比如下面的窗体:
  生成的代码如下这么多,可见设计器出力不少。
  注:下面代码只是为了让你看它有多长,不需要仔细研究。 namespace WinFormDemo04{    partial class Form1    {        ///         ///  Required designer variable.        ///         private System.ComponentModel.IContainer components = null;        ///         ///  Clean up any resources being used.        ///         /// true if managed resources should be disposed; otherwise, false.        protected override void Dispose(bool disposing)        {            if (disposing && (components != null))            {                components.Dispose();            }            base.Dispose(disposing);        }        #region Windows Form Designer generated code        ///         ///  Required method for Designer support - do not modify        ///  the contents of this method with the code editor.        ///         private void InitializeComponent()        {                    this.button1 = new System.Windows.Forms.Button();            this.textBox1 = new System.Windows.Forms.TextBox();            this.comboBox1 = new System.Windows.Forms.ComboBox();            this.listBox1 = new System.Windows.Forms.ListBox();            this.label1 = new System.Windows.Forms.Label();            this.treeView1 = new System.Windows.Forms.TreeView();            this.dataGridView1 = new System.Windows.Forms.DataGridView();            this.gridId = new System.Windows.Forms.DataGridViewTextBoxColumn();            this.gridName = new System.Windows.Forms.DataGridViewTextBoxColumn();            this.pictureBox1 = new System.Windows.Forms.PictureBox();            this.radioButton1 = new System.Windows.Forms.RadioButton();            this.checkBox1 = new System.Windows.Forms.CheckBox();            ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();            this.SuspendLayout();            //             // button1            //             this.button1.Location = new System.Drawing.Point(35, 27);            this.button1.Name = "button1";            this.button1.Size = new System.Drawing.Size(75, 23);            this.button1.TabIndex = 0;            this.button1.Text = "button1";            this.button1.UseVisualStyleBackColor = true;            this.button1.Click += new System.EventHandler(this.button1_Click);            //             // textBox1            //             this.textBox1.Location = new System.Drawing.Point(203, 27);            this.textBox1.Name = "textBox1";            this.textBox1.Size = new System.Drawing.Size(100, 23);            this.textBox1.TabIndex = 1;            this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);            //             // comboBox1            //             this.comboBox1.FormattingEnabled = true;            this.comboBox1.Location = new System.Drawing.Point(325, 26);            this.comboBox1.Name = "comboBox1";            this.comboBox1.Size = new System.Drawing.Size(121, 25);            this.comboBox1.TabIndex = 2;            this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);            //             // listBox1            //             this.listBox1.FormattingEnabled = true;            this.listBox1.ItemHeight = 17;            this.listBox1.Items.AddRange(new object[] {            "111",            "222",            "aaa"});            this.listBox1.Location = new System.Drawing.Point(199, 84);            this.listBox1.Name = "listBox1";            this.listBox1.Size = new System.Drawing.Size(120, 89);            this.listBox1.TabIndex = 3;            this.listBox1.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged);            //             // label1            //             this.label1.AutoSize = true;            this.label1.Location = new System.Drawing.Point(138, 30);            this.label1.Name = "label1";            this.label1.Size = new System.Drawing.Size(43, 17);            this.label1.TabIndex = 4;            this.label1.Text = "label1";            this.label1.Click += new System.EventHandler(this.label1_Click);            //             // treeView1            //             System.Windows.Forms.TreeNode treeNode1 = new System.Windows.Forms.TreeNode("节点1");            System.Windows.Forms.TreeNode treeNode2 = new System.Windows.Forms.TreeNode("节点2");            System.Windows.Forms.TreeNode treeNode3 = new System.Windows.Forms.TreeNode("节点0", new System.Windows.Forms.TreeNode[] {            treeNode1,            treeNode2});            System.Windows.Forms.TreeNode treeNode4 = new System.Windows.Forms.TreeNode("节点4");            System.Windows.Forms.TreeNode treeNode5 = new System.Windows.Forms.TreeNode("节点5");            System.Windows.Forms.TreeNode treeNode6 = new System.Windows.Forms.TreeNode("节点3", new System.Windows.Forms.TreeNode[] {            treeNode4,            treeNode5});            this.treeView1.Location = new System.Drawing.Point(325, 84);            this.treeView1.Name = "treeView1";            treeNode1.Name = "节点1";            treeNode1.Text = "节点1";            treeNode2.Name = "节点2";            treeNode2.Text = "节点2";            treeNode3.Name = "节点0";            treeNode3.Text = "节点0";            treeNode4.Name = "节点4";            treeNode4.Text = "节点4";            treeNode5.Name = "节点5";            treeNode5.Text = "节点5";            treeNode6.Name = "节点3";            treeNode6.Text = "节点3";            this.treeView1.Nodes.AddRange(new System.Windows.Forms.TreeNode[] {            treeNode3,            treeNode6});            this.treeView1.Size = new System.Drawing.Size(121, 97);            this.treeView1.TabIndex = 5;            this.treeView1.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView1_AfterSelect);            //             // dataGridView1            //             this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;            this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {            this.gridId,            this.gridName});            this.dataGridView1.Location = new System.Drawing.Point(30, 209);            this.dataGridView1.Name = "dataGridView1";            this.dataGridView1.Size = new System.Drawing.Size(258, 150);            this.dataGridView1.TabIndex = 6;            this.dataGridView1.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellContentClick);            //             // ID            //             this.gridId.HeaderText = "ID";            this.gridId.Name = "ID";            //             // GridName            //             this.gridName.HeaderText = "Name";            this.gridName.Name = "GridName";            //             // pictureBox1            //             this.pictureBox1.Location = new System.Drawing.Point(321, 221);            this.pictureBox1.Name = "pictureBox1";            this.pictureBox1.Size = new System.Drawing.Size(100, 50);            this.pictureBox1.TabIndex = 7;            this.pictureBox1.TabStop = false;            this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click);            //             // radioButton1            //             this.radioButton1.AutoSize = true;            this.radioButton1.Location = new System.Drawing.Point(33, 89);            this.radioButton1.Name = "radioButton1";            this.radioButton1.Size = new System.Drawing.Size(102, 21);            this.radioButton1.TabIndex = 8;            this.radioButton1.TabStop = true;            this.radioButton1.Text = "radioButton1";            this.radioButton1.UseVisualStyleBackColor = true;            this.radioButton1.CheckedChanged += new System.EventHandler(this.radioButton1_CheckedChanged);            //             // checkBox1            //             this.checkBox1.AutoSize = true;            this.checkBox1.Location = new System.Drawing.Point(33, 125);            this.checkBox1.Name = "checkBox1";            this.checkBox1.Size = new System.Drawing.Size(89, 21);            this.checkBox1.TabIndex = 9;            this.checkBox1.Text = "checkBox1";            this.checkBox1.UseVisualStyleBackColor = true;            this.checkBox1.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged);            //             // Form1            //             this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;            this.ClientSize = new System.Drawing.Size(497, 418);            this.Controls.Add(this.checkBox1);            this.Controls.Add(this.radioButton1);            this.Controls.Add(this.pictureBox1);            this.Controls.Add(this.dataGridView1);            this.Controls.Add(this.treeView1);            this.Controls.Add(this.label1);            this.Controls.Add(this.listBox1);            this.Controls.Add(this.comboBox1);            this.Controls.Add(this.textBox1);            this.Controls.Add(this.button1);            this.Margin = new System.Windows.Forms.Padding(2);            this.Name = "Form1";            this.Text = "Form1";            this.Load += new System.EventHandler(this.Form1_Load);            ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();            this.ResumeLayout(false);            this.PerformLayout();        }        #endregion        private Button button1;        private TextBox textBox1;        private ComboBox comboBox1;        private ListBox listBox1;        private Label label1;        private TreeView treeView1;        private DataGridView dataGridView1;        private PictureBox pictureBox1;        private RadioButton radioButton1;        private CheckBox checkBox1;        private DataGridViewTextBoxColumn gridId;        private DataGridViewTextBoxColumn gridName;    }}
  一个class中的成员可以是字段,属性,方法,构造函数,析构函数,事件,索引器,重载运算符,常量,内部嵌套类。通常,一个类库中的class,属性和方法是最常见的,到可视化窗体或控件类时,属性和事件是最常见的,这是因为通过电脑输入设备或内部的动作,会触发很多事件,这些事件会调用我们订阅的方法,从而完成业务的流转。所以学习可视化控件,就是学习他的属性和事件。每个控件,双击后自动订阅的事件就是这个控件最常用的控件,比如Button的Click,TextBox的TextChanged事件等。
  有一些控件还有子控件或子选项,就像一个类型的一个属性是集合类型一些,可以添加子类型。有一些控件是容器控件,用来承载其他控件的,它有一个Controles的属性,可以添加其他类型的控件。
  关于每个控件的使用这里就不展开了,因为相关的资料很多,官方的文档就是不错的选择。
  在WinForm中,大部分事件都是以xxxEventHandler作为定义事件的委托,并且有两个参数,第一个是object sender,就是发出事件的控件,第二个参数是EventArgs或它的子类,如果是它子类,会携带一些事件的参数。xxxEventHandler和xxxEventArgs与EventHandler和EventArgs是委托和参数的关系,也是对应的。   private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e){}
  比如DataGridViewCellEventHandler和DataGridViewCellEventArgs,并且Args中有当前单元格的行与列下标。
  学习控件是一个细活,一个一个过,关注他们的属性,事件,虽然方法比较少,但也是要关注的,就像研究一个类,就要看他的成员都有什么,各自作用是什么一样。

建议家长有钱没钱,常给孩子吃这菜,简单易学,营养解馋身体棒到了春天,很多人情绪很低落,非常容易春困,特别容易疲倦,整天的精气神非常差,平常的胃口很差,食欲明显下降,如果家里有孩子,家长一定要满足孩子的营养,多给孩子吃绿色蔬菜,今天推荐我家每天洗澡和一周洗一次澡,身体有啥区别?听听医生的解答随着物质生活不断提高,人们在养生方面有了巨大改观。除去饮食锻炼睡眠喝水外,还特别注重卫生清洁。因为一旦不注重卫生,身体就像一个巨大的细菌培养皿,使得病毒大量寄生,预防感染危害健康。女神黑科技免洗头喷雾真能代替洗头吗?来看看医生的实验钱江晚报小时新闻记者杨茜通讯员王文婷油性头皮天气太热没有时间头发油腻的理由有一千种。但是,对于很多女生来说,只要不出门,那就可以不洗头。于是,免洗头喷雾在网上热销,号称只要摇一摇喷睡觉老是在半夜醒来,是得了什么病?医生可能是肝脏出现了问题王先生今年56岁,这段时间心情十分郁闷,每天晚上不仅入睡困难,好不容易睡着了,半夜也常常醒来,然后就再也睡不着了。由于长时间的睡眠不足,王先生精神状态逐渐变差,工作时也受到了很大的如何祛痘才真正有效?记住这3个阶段,有效护肤才能避免反复长痘对于皮肤经常性长痘问题,不少人认为是皮肤过度分泌油脂所致。一般情况下,油性肌肤相比其它肤质似乎更容易出现痘痘问题。不过油脂分泌旺盛,其实并非皮肤长痘的根源。油脂只是导致皮肤长痘的其最新研究!咖啡真的很健康,心脏不好的人喝了也有好处咖啡茶叶可可是世界公认的三大饮料,在全球范围内都备受欢迎。对于中国人而言,此前茶叶一直是中国人最主要的饮品,近年来,随着社会经济的发展,咖啡逐渐受到很多人的青睐。然而,在很多中国人血脂高该怎么吃?这份饮食指南请收好本期热门话题,我们来聊一聊血脂高在饮食上需要注意什么。怎样才能从高血脂到血脂正常?赵慧君中国注册营养师相信很多人的体检报告上,都会有血脂高这个标签。高血脂属于一种慢性代谢性疾病,受春饮茶,护健康,这几种茶水,降火杀菌护肝防感冒,别错过饮茶,自古以来,就是延年益寿的好习惯。而春季,天气干燥,正是饮茶的好时机,千万别错过。常饮茶,可提升醒脑缓解春困,提高工作和学习的效率。尤其是下面这几种茶饮,不仅适合春季饮用,还可哺乳期产妇要少吃这些食物,会导致产后回奶,宝宝口粮不保女性在哺乳期的时候一定要多补充一些营养,但是并不代表着什么东西都是可以吃的,在面对这个问题的时候还是需要忌口的。如果说经常吃这些东西的话,那么就会导致产后回奶,这样一来孩子的口粮就健康新观念现今物质生活的提高资讯的发达。我们是越来越关注营养和健康了。我们不单要吃得饱,还要吃得好吃得对!!食物种类多样通过各种途径,我们了解到了早上要吃好中午要吃饱晚上要吃少,也懂得了食物12种保护大脑免受衰老和痴呆的常见食物如果有人告诉你,你可以通过吃更多美味的有益健康的食物来保护你的大脑免受与年龄有关的疾病,如阿尔茨海默氏症和痴呆症,你不会这样做吗?谁不会!虽然运动和遗传对大脑健康起着重要作用,但饮
动视使命召唤现代战争将于3月17日开启多人游戏免费试玩IT之家3月15日消息,动视官方今日宣布,使命召唤将于北京时间3月17日凌晨1点开启使命召唤现代战争2免费试玩活动,持续时间到3月21日,共计五天,期间将为玩家提供部分多人游戏内容学林随笔交大教授我跑了30多座城市,发现老龄化社会的一个秘密前些年,我到广西北海调研,遇到一位来自吉林的老人。老人告诉我,东北的冬天来得早,国庆节后就开始有点冷了,直到来年劳动节后才真正暖和起来。他们退休后,就开始设法到南方避寒,过上了短则香港文体旅局局长吸引旅客留港之余也去大湾区内地城市游玩随着与内地全面恢复通关,香港冰封3年多的旅游业迎来复苏。近日,香港特区政府文化体育及旅游局局长杨润雄积极推介香港旅游,他表示将力推一程多站式旅游,让访港旅客体验不一样的香港之余,也期待更多城市实现母婴室全覆盖程汉鹏近日,记者从广东省妇联了解到,近年来广东省加快推动公共场所母婴室建设,目前建成母婴室共9492间,仅2022年新改扩建1175间。此外,在母乳喂养地方性法规母婴室安全标准规范海兰德谈快船专机遭雷击ampampamp引擎短暂熄火当时我们都以为芭比q了直播吧3月16日讯据快船随队记者OhmYoungmisuk报道,在美国当地时间2月25日,快船全队飞往丹佛的旅途中,快船的转机曾被闪电击中。记者称,当时飞机曾多次下调飞行高度,一些文明城市大家建丨青白江桃花沟里的另一道风景线阳春三月,微风和煦正是出游踏青的好时节上个周末姚渡镇千亩桃园迎来了人从众模式除了娇媚的桃花如织的游人景区里的志愿者也成了一道靓丽的风景线巡逻之余,他们当起反诈导游01hr周末两天,ampampquot超越传统计算的未来量子芯片冰箱的背后故事ampampquot中国团队研制成功量子芯片冰箱传统计算是指利用经典物理学的规律和计算机科学的方法,以二进制形式处理和存储数据的计算方式,即使用逻辑门结合二进制数据进行计算。逻辑门传统计算机的逻辑门包西安稳居第四,天津落后南京,中国十大新一线城市排行榜城市的变化与发展往往是融合各种力量共同发展的复杂产物,建设一座城市,无论规模多大,都不是一件容易的事。今天,我们对城市的认识完全是从经济定位和各种优势来分析的,国内经济学家对城市的日照即将新开3条航线!可飞这18个城市!自2023年3月26日起将执行夏航季航班计划夏航季日照机场新开福州天津南昌航线通航城市达18个北京,上海,广州,深圳成都,重庆,杭州,武汉,长沙南昌,海口,昆明,福州天津,哈尔滨,沧州银行在河北省内其他城市开设的64家银行明细及分类分析截止目前,沧州银行在河北省内共开设有64家银行,其中一分行开设情况。截止目前,沧州银行共在河北省内其他城市开设有9家分行,张家口承德外未开设分行。(排名不分先后)1。沧州银行股份有聚焦315文旅市场回暖请查收避坑攻略谁砸了甘孜旅游我砸他饭碗。这句话出自甘孜文旅局长刘洪。短短半个月内,甘孜因为游客投诉事件两次被挂上微博热搜。2月下旬,有网友在短视频平台爆料甘孜康定祥驴酒店经营问题3月8日,有游客