设置窗体的起始位置,并检查配置文件是否存在,存在使用配置文件,不存在创建配置文件,在每次打开窗体时保持窗体上一次关闭的位置。
2014-04-01 12:41
801 查看
//设置窗体的起始位置
//检查配置文件是否存在
if (File.Exists("config.dat"))
{
Point p;
//存在使用配置文件
using (FileStream file = new FileStream("config.dat", FileMode.Open, FileAccess.Read))
{
BinaryFormatter bf = new BinaryFormatter();
p = (Point)bf.Deserialize(file);
this.StartPosition = FormStartPosition.Manual;
this.Location = p;
}
//读取配置文件中的信息
using (FileStream f = new FileStream("config.dat", FileMode.Open, FileAccess.Read))
{
BinaryFormatter b = new BinaryFormatter();
p = (Point)b.Deserialize(f);
}
}
else
{
//不存在创建配置文件
this.StartPosition = FormStartPosition.CenterScreen;
}
//窗体关闭时掉用的起始位置。
protected override void Dispose(bool disposing)
{
//保存配置文件
using (FileStream file = new FileStream("config.dat", FileMode.Create, FileAccess.Write))
{
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(file, this.Location);
}
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
//检查配置文件是否存在
if (File.Exists("config.dat"))
{
Point p;
//存在使用配置文件
using (FileStream file = new FileStream("config.dat", FileMode.Open, FileAccess.Read))
{
BinaryFormatter bf = new BinaryFormatter();
p = (Point)bf.Deserialize(file);
this.StartPosition = FormStartPosition.Manual;
this.Location = p;
}
//读取配置文件中的信息
using (FileStream f = new FileStream("config.dat", FileMode.Open, FileAccess.Read))
{
BinaryFormatter b = new BinaryFormatter();
p = (Point)b.Deserialize(f);
}
}
else
{
//不存在创建配置文件
this.StartPosition = FormStartPosition.CenterScreen;
}
//窗体关闭时掉用的起始位置。
protected override void Dispose(bool disposing)
{
//保存配置文件
using (FileStream file = new FileStream("config.dat", FileMode.Create, FileAccess.Write))
{
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(file, this.Location);
}
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
相关文章推荐
- 检查一个路径下文件是否存在,如果不存在设置一个定时器,在定时器内每隔一定时间检查一次,直到该文件存在返回成功,或者定时超时返回失败
- 【转】通过文件锁实现,程序开始运行时,先判断文件是否存在,若存在则表明该程序已经在运行了,如果不存在就用open函数创建该文件,程序退出时关闭文件并删除文件
- 通过文件锁实现,程序开始运行时,先判断文件是否存在,若存在则表明该程序已经在运行了,如果不存在就用open函数创建该文件,程序退出时关闭文件并删除文件。
- C# winfrom判断文件是否存在,不存在则创建,否则读取值显示到窗体
- 通过文件锁实现,程序开始运行时,先判断文件是否存在,若存在则表明该程序已经在运行了,如果不存在就用open函数创建该文件,程序退出时关闭文件并删除文件
- 根据文件获取文件夹,判断文件夹是否存在,不存在则创建
- 在config配置文件添加iis的Mime类型,检测文件中是否存在添加语句,使用xml解析方法
- ArcGIS Server 创建站点的时候出错。配置存储位置中包含有其他站点正在使用的服务器配置文件。
- ADPLUS使用配置文件设置断点时无法创建DUMP文件原因分析
- 动软代码生成器,出现”添加服务器配置失败,请检查是否有写入权限或文件是否存在“的错误的解决办法
- java 写的检查文件存在性,如果不存在创建文件
- c/c++ 检查指定目录是否存在,不存在则创建改目录
- C语言文件操作 fopen, fclose, mkdir(打开关闭文件,建文件夹,判断文件是否存在可读或可写)
- 动软中,在连接服务器时,出现“添加服务器配置失败,请检查是否有写入权限或文件是否存在“错误
- python判断文件是否存在,不存在就创建一个
- 关于判断MDI窗体是否存在,存在则显示,不存在则创建
- ADPLUS使用配置文件设置断点时无法创建DUMP文件原因分析
- C语言文件操作 fopen, fclose, mkdir(打开关闭文件,建文件夹,判断文件是否存在可读或可写)
- 检查目录是否存在,不存在则创建之
- 检查给定目录是否存在,如果不存在则创建该目录