C#学习笔记1

来源:互联网 发布:手机网络爸爸 编辑:程序博客网 时间:2024/04/30 05:32

今天学习中国大学慕课MOOC当中的C#程序设计

了解C#程序的基本架构。

源程序文件.cs

工程文件.csproj

解决方案.sln

其他辅助文件

编译/运行   

编译生成中间代码,

发布

       直接复制

在资源管理器中,可以打开解决方案的文件夹,在debug中会生成.exe文件,可以直接在计算机当中运行。

面向对象的核心概念

对象三要素

1.属性(property)

label1.Text, this.BackColor 表示一种状态

2.方法(method)

xxx.SetBounds(x,y,w,h);表示对象的一个动作,一个功能

3.事件(event)

表示这个对象跟外部事物的一种互动。

this.button1.Click+= new System.EventHandler(this.button1_Click);

例子

using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("你好!");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Text = "这是一个程序";
            this.BackColor = Color.FromArgb(255, 255, 0);
            this.label1.SetBounds(100, 100, 200, 50);
        }

        private void Form1_MouseMove(object sender, MouseEventArgs e) // sender是表示谁发出的事件,e是具体鼠标移动情形
        {
            this.label1.Text = e.X + "," + e.Y;
        }
    }
}
这就是入门书写的一些基础语句,文件名为Form1.cs文件。今天写了这么多,明天继续努力。

0 0