form1.cs
来自「Visual C#2005程序设计教程」· CS 代码 · 共 55 行
CS
55 行
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace LT14_2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.Text = "try—finally语句示例";
label1.Text = "源 文 件";
label2.Text = "";
button1.Text = "检 查";
button2.Text = "退 出";
}
private void button1_Click(object sender, EventArgs e)
{
try
{
if (File.Exists(textBox1.Text)) // 判断文件是否存在
{
label2.Text = "该文件存在";
}
else
{
label2.Text = "该文件不存在";
}
}
finally // 无论是否发生异常,都正常结束
{
MessageBox.Show("感谢使用本软件!","程序结束");
}
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?