您的位置:首页 > 职场人生

黑马程序员-我的入学笔记6-winform的初次了解

2013-09-26 13:45 267 查看
---------------------- <a href="http://edu.csdn.net" target="blank">ASP.Net+Android+IO开发S</a>、<a
href="http://edu.csdn.net" target="blank">.Net培训</a>、期待与您交流! ----------------------

  winform的这段视频(包括后面的HTML),只是初步的讲解了一些常用控件的用法,具体的应用,我还是不了解,这里就写我的一些初步的了解.

  从概念上,通过WinForm在案例中我理解了类、对象、属性、方法、事件、索引器等的初步概念.winform中最主要的是控件,控件是对属性和方法进行了封装,我们将控件拖入到窗口中,VS会自动帮我们生成控件的相关属性和方法,我们在通过写方法的具体应用,由用户来决定什么时候调用方法,这应该就是事件吧.(关于事件和委托,如果去搜索总是让人觉得很复杂,我觉得应该和接口差不多,通过接口调用方法,以后再做深入的了解)

  关于控件,最主要的有button控件,text控件,combobox控件,label控件,listbox控件,picturebox控件,checkbox控件,radiobutton控件等.再以后的多多接触中这些控件的用法,应该不算很难,关键的应该是后天程序的实现.刚接触时,真的不知所以然,在想控件是怎么实现的,后面的代码是怎么样的.我自己的理解过程是这样的.

  第一,每个项目中都会自动生成以个Program类,类中有一个方法,方法中掉用了三个方法

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace 笔记
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
//我只是初步的了解,要想真正的了解,还要不断的学习

//这里调用了Application类的EnableVisualStyles方法,用于绘制
Application.EnableVisualStyles();
//将某些控件上定义的 UseCompatibleTextRendering 属性设置为应用程序范围内的默认值
Application.SetCompatibleTextRenderingDefault(false);
//在当前线程上开始运行标准应用程序消息循环
Application.Run(new Form1());
}
}
}

  第二,一个空白的Form1窗口类,初始的状态是
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 笔记
{
//partial 分部类型定义允许将类、结构或接口的定义拆分到多个文件中。
//创建了一个继承Form的子类Form1
public partial class Form1 : Form
{
//类的构造方法
public Form1()
{
//这是Form1自动生成的一个方法,初始化成分的方法
InitializeComponent();
}
}
}

  在这里我在看看InitializeComponent()方法的定义是怎么样的,看着有些复杂,不过构造函数肯定是用来传参的,他放在一个类中

namespace 笔记
{
partial class Form1
{
/// <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.SuspendLayout();
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 262);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}

#endregion

}
}

当拖入控件后,InitializeComponent()中会自动添加按钮的参数,事件的方法定义也在其中
this.button1 = new System.Windows.Forms.Button();

this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(23, 30);
//控件的姓名
this.button1.Name = "button1";
//控件的大小
this.button1.Size = new System.Drawing.Size(75, 23);
//Tab键的顺序
this.button1.TabIndex = 0;
//按钮上的文本
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
//在单击控件时发生的button1_Click方法
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(105, 31);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(100, 21);
this.textBox1.TabIndex = 1;

通过查看了代码,才能对程序的运行过程有一定的了解后,才能知其然知其所以然,有一个更深入的了解.

  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: