1.c#第一个控制台程序
1.新建项目 选择控制台应用
2.在problem.cs中输入以下代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Test1_1
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("hello this is my first c# problem");
}
}
}
执行结果如下
2.c#第一个window程序
在test1_2.cs中输入以下代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Test1_2
{
public partial class Test1_2 : Form
{
public Test1_2()
{
InitializeComponent();
}
private void Test1_2_Load(object sender, EventArgs e)
{
//设置本窗体的标题文字
this.Text = "我的第一个window程序";
//先创建标签控件,再设置其显示文本和位置等属性
Label lblShow = new Label();
lblShow.Location = new Point(50, 60);
lblShow.AutoSize = true;
lblShow.Text = "本程序由陈树娟设计,欢迎您使用!";
//将标签控件添加到本窗体之中
this.Controls.Add(lblShow);
}
}
}
执行结果如下:
3.一个具有输出功能的窗体应用程序
在设计窗口中拖入label testBox 以及button标签
接着修改响应的属性项,变成下面的样子
最后为控件添加事件方法 代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Test1_3
{
public partial class Test1_3 : Form
{
public Test1_3()
{
InitializeComponent();
}
private void btnOk_Click(object sender, EventArgs e)
{
//定义字符串变量
string strResult;
//提取在文本框中输入的文字
strResult = txtName.Text + ",你好,欢迎使用本程序";
//显示结果
lblResult.Text = strResult;
}
}
}
运行结果如下: