一、Directory类
File:文件
Path:路径
FileStream:流文件
StreamReader:流文件
StreamWriter:流文件
//创建指定文件夹 重复创建不会替换掉之前同名的文件夹
Directory.CreateDirectory(@"C:\Users\FengZZZ\Desktop\new");
Console.WriteLine("创建成功");
//删除指定文件夹 如果文件夹不为空,则报错
Directory.Delete(@"C:\Users\FengZZZ\Desktop\new");
Console.WriteLine("删除成功");
//文件夹不为空的情况下强制删除
Directory.Delete(@"C:\Users\FengZZZ\Desktop\new",true);
//指定文件夹剪切
Directory.Move("原文件夹地址", "目标文件夹地址");
//读取指定文件夹下所有文件的路径
string[] path = Directory.GetFiles(@"C:\Users\FengZZZ\Desktop\new");
//读取指定文件夹下所有指定文件格式的路径
string[] path2 = Directory.GetFiles(@"C:\Users\FengZZZ\Desktop\new","*.jpg");
//获得指定文件内所有文件夹的路径
string[] path3 = Directory.GetDirectories(@"C:\Users\FengZZZ\Desktop\new");
//判断指定文件夹内是否存在
Directory.Exists(@"C:\Users\FengZZZ\Desktop\new");
Console.ReadKey();
二、WebBrowser控件
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string str = textBox1.Text;
Uri uri = new Uri("http://"+str);
webBrowser1.Url = uri;
}
三、日期选择器
ComboBox下拉框控件
DropDownStyle:控制下拉框的外观样式
DateTime.Today.Year:获取当前时间
public Form1()
{
InitializeComponent();
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
//避免重复赋值,赋值前清空
comboBox2.Items.Clear();
for (int i = 1; i <= 12; i++)
{
comboBox2.Items.Add(i + "月");
}
}
private void Form1_Load(object sender, EventArgs e)
{
int yearNow = DateTime.Today.Year;
for (int i = yearNow; i >= 1949; i--)
{
comboBox1.Items.Add(i + "年");
}
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
comboBox3.Items.Clear();
//拿到前两个下拉框中选中的年份和月份在下拉框集合中的坐标
int yearSelected = comboBox1.SelectedIndex;
int monthSelected = comboBox2.SelectedIndex;
//根据坐标拿到选中的年和月的数值便于计算
int yearStr = Convert.ToInt32(comboBox1.Items[yearSelected].ToString().Split(new char[] { '年' })[0]);
int monthStr = Convert.ToInt32(comboBox2.Items[monthSelected].ToString().Split(new char[] { '月' })[0]);
int day = 0;
//判断月和年赋予日期值
switch (monthStr)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
day = 31;