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

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中有当前单元格的行与列下标。
  学习控件是一个细活,一个一个过,关注他们的属性,事件,虽然方法比较少,但也是要关注的,就像研究一个类,就要看他的成员都有什么,各自作用是什么一样。

油价上涨,不管你有没有车,都会受到影响与时俱进,我进入跑步上班时代疫情爆发开始,国际紧张局势已经影响到了各行各业。目前国内油价已经刷下历史新高上周油价上涨已经突破9元时代,接下来下一次的调整应该在6月14日左右,继续上体验金海狮露营车向往的露营生活,原来可以如此简单近两年因为国内外疫情原因导致中长距离出游受到了很大限制,于是露天开放的近郊露营则成了人们休闲放松的一个热门项目。但高质量的露营并不只是简单地搭个帐篷,摆几张折叠桌椅,不仅需要整理繁鹈鹕谈判破裂,魔术守株待兔!锡安单换两状元,新的奥尼尔要来了本赛季已经临近尾声,只剩下最后两支球队还没有放假。其他28支球队都相继把目光投向了,交易市场也自然热闹了不少。今年休赛期,大牌的自由球员并不多,所以,但部分球队还是把球队补强寄希望如果你在大西洋遇见一艘无人驾驶的船,它可能真不是幽灵船人类赖以生存的蓝星,表面有70的部分是海洋,广袤的海洋是许多生物的家园,也是调节地球气候的重要部分。因此,对于海洋的了解与探索就成了人类长久的课题。图片来自NASA大多数海洋学采样海湾国家的机场不是都好,科威特机场被评为世界上第二烂海湾几个国家里都是富国,他们的基础设施应该也不会太差,比如举世闻名的迪拜国际机场,卡塔尔的哈马德国际机场,沙特吉达的新机场也是十分气派,阿曼马斯喀特新机场也是非常现代,目前貌似只有看海狮表演,六一儿童节海底世界等你来玩来源长沙晚报网长沙晚报掌上长沙5月31日讯(全媒体记者贺文兵通讯员陈俏)看人鱼共舞,观海狮表演,逛复古市集,6月1日至5日,结合儿童节与端午节,长沙海底世界特别推出童心闹海洋粽情端8000万年前人类身体大小的菊石曾生活在大西洋目前,最新考古研究显示,大约8000万年前,人类身体大小的远古菊石在大西洋中游动,它们拥有较长的触臂,螺旋外壳直径达到1。8米,该物种是迄今世界上最大的菊石,它们是灭绝的海生无脊椎凯勇第三战健康的小伙子凯勇第三战健康的小伙子赛前,乌度卡说,我们很健康。其实我们都知道他说的什么,也知道他想做什么。当我们都以为是烟雾弹的时候,健康的凯尔特人给了勇士当头一棒。因为,我们都知道,伤病不可范佩西永远感激曼联球迷的热情但为了孩子只好拒绝曼联每日镜报曼彻斯特方面记者DavidMcDonnell更新了独家专栏,报道了为什么范佩西拒绝了滕哈格的邀约。范佩西说曼联的球迷对我的尊重让我受宠若惊,当我在几年后和费内巴切一起回归,退休之后,不要去这两种人家里串门年轻的时候,想要抽出时间去串门,是很奢侈的事情。因此,人们常常会在分别的时候说改天一起吃饭啊!改天一定聚啊!但改天是哪天,并没有确切和确定的日期,更多的只是一种愿景罢了。退休了,就故宫秘境,带你窥见神秘的宫殿往事太和殿坤宁宫神武门溥仪崇祯护城河角楼当这些元素交织在一起时,我们会自然地想到一个让人感到陌生又熟悉的词语故宫。如今的故宫,是深受国人追捧的文化IP。国家宝藏让我们窥见故宫的神秘一角
NBA75大巨星入选剖析NBA詹姆斯利拉德科比笔者曾经在NBA公布即将评选75大巨星时做过一个预测文章,现在回顾一下这个,看看哪些猜对了哪些又谬之千里。首先,我们来回顾下96年的50大巨星名单通过对比我们好听的WeChat英文名文案1。Deity你是地狱里指引迷路的神,不容任何人玷污半分。2。livresse酒后伴着微醺体味的那种沉醉和快乐。3。LAYDOWN我对你仍然向往,但不再抱任何希望。4。REGRET从NBA到CBA,林书豪为何会被NBA联盟淘汰?如今林书豪已经被NBA淘汰出局了,尽管还有很多,但这已经成了固定的事实,即使未来有NBA球队有意签回他,那么他也会是球队的板凳尾端人物,很难再获得更多的出场轮换时间。作为球员生涯,郭艾伦缺阵首场比赛事出有因,姚明动真格郭少恐要付出惨痛代价近日CBA常规赛也是火热开战,在今天的辽宁男篮也是迎来了本赛季的首场比赛,最终的辽宁队是以10789大胜广州队,从而也赢得了赛季的开门红,但是辽宁男篮并非完整阵容,球队的核心郭艾伦特别现实的文案可能我太封建了我觉得暧昧只能和一个人搞恋爱只能和一个人谈一个人不能吃两个人的饭。长大就不要问别人为什么离开了没结局的故事太多了有谁不遗憾呢是我的爱太小声还是你假装听不见。我见过你最千年岳麓书院为什么行岳麓书院。视觉中国供图岳麓书院,在今日大众心中可能是一座古建筑一处历史旅游景点。而绵延千年的它,更是我国古代一种独特的教育组织形式的代表,反映的是在一座幽静闲适的院落中,一群读书人孩子早餐别只会吃面条了,教你做柔软拉丝小面包,做法简单又好吃孩子早餐别只会吃面条了,教你做柔软拉丝小面包,做法简单又好吃。天冷了,作为家有学生党的宝妈,没有暖气的日子,早上起床真靠勇气,冻手冻脚的准备早餐,真是能偷懒就偷懒,争取10分钟做好晚间悦读有一种感恩,是理解别人的付出1感恩,是一种美德,是一种境界。这个世界上,没有人会无缘无故对你好,所有对你的好,你都应该珍惜。一个人,受过多少苦楚无所谓,遇到多少坎坷也无所谓,怕就怕,付出没有人在乎,坚持没有人红色文旅人气旺来源人民网人民日报游客在贵州遵义市遵义会议会址参观。人民视觉核心阅读依托革命旧址纪念馆博物馆等革命传统资源发展红色旅游,既能满足人民群众出门旅行领略祖国大好河山的美好需求,又能满足孩子的九大敏感期孩子在出生的时候以及在成长的过程中或多或少的变的有些敏感,这是必不可少,我们要观察孩子是的敏感期作出相对应的方法提升宝宝的心理健康和又一个好的成长心态尤为关键。我们知道一岁左右是孩我和我的女儿还有她的女儿祝我家大宝和小宝节日快乐。妈妈的女儿和女儿的女儿你们好,今天是女儿的节日,虽然女儿你也孕育了女儿,但你始终是妈妈的大宝,妈妈爱着你和你的女儿。女儿又有个小宝在肚子里世上做妈妈的,没