您的位置:首页 > 编程语言 > C#

c#对话框

2016-05-10 09:06 465 查看
OpenFileDialog open = new OpenFileDialog();//创建对话框
open.InitialDirectory = @"C:\Documents and Settings\All Users\桌面"; //设置对话框路径
open.Title = "对话框1"; //对话框标题
open.Filter = "文本文档|*.txt|所有文件|*.*";
open.Multiselect = true; //多选
open.ShowDialog(); //打开对话框
//string[] paths = open.FileName;
string paths = open.FileName;  //读取文件的全路径
if (paths == "") return;
using (FileStream file = new FileStream(paths, FileMode.OpenOrCreate, FileAccess.Read))
{
byte[] bytes = new byte[1024 * 1024 * 5];
int r = file.Read(bytes, 0, bytes.Length);
this.textBox1.Text = Encoding.Default.GetString(bytes, 0, r);
}


  

int temp=0;
int[] a = { 23, 44, 66, 76, 98, 11, 3, 9, 7 };
for (int i = 0; i < a.Length; i++)
{
for (int j = 0; j < a.Length-i-1; j++)
{
if (a[j] < a[j + 1])  //从大到小
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}

}
Console.WriteLine("排序后的数组:");
foreach (int item in a)
{
Console.Write(item + " ");
}
Console.WriteLine();
Console.ReadKey();


  

SaveFileDialog sd=new SaveFileDialog(); //创建
// 保存文件对话框
sd.InitialDirectory = @"C:\Documents and Settings\All Users\桌面"; //设置对话框路径
sd.Title = "对话框1"; //对话框标题
sd.Filter = "文本文档|*.txt|所有文件|*.*";
sd.ShowDialog();
string path = sd.FileName;
using (FileStream fsv = new FileStream(path, FileMode.Create, FileAccess.Write))
{
byte[] bytes = Encoding.Default.GetBytes(this.textBox1.Text);
fsv.Write(bytes, 0, bytes.Length);
}


  

private void button3_Click(object sender, EventArgs e)
{
FontDialog fonts = new FontDialog();

fonts.ShowDialog();
this.textBox1.Font = fonts.Font;
}

private void button4_Click(object sender, EventArgs e)
{
ColorDialog color = new ColorDialog();
color.ShowDialog();
this.textBox1.BackColor = color.Color;
this.textBox1.ForeColor = color.Color;
}


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