您的位置:首页 > 其它

从上次关闭窗口的位置启动窗口

2014-02-20 14:39 260 查看
public partial class Frm_Main : Form
{
public Frm_Main()
{
InitializeComponent();
}

private void Frm_Main_Load(object sender, EventArgs e)
{
RegistryKey myReg1, myReg2;//声明注册表对象
myReg1 = Registry.CurrentUser;//获取当前用户注册表项
try
{
myReg2 = myReg1.CreateSubKey("Software\\MySoft");//在注册表项中创建子项
this.Location = new Point(Convert.ToInt16(myReg2.GetValue("1")), Convert.ToInt16(myReg2.GetValue("2")));//设置窗体的显示位置
}
catch { }
}

private void Frm_Main_FormClosed(object sender, FormClosedEventArgs e)
{
RegistryKey myReg1, myReg2;//声明注册表对象
myReg1 = Registry.CurrentUser;//获取当前用户注册表项
myReg2 = myReg1.CreateSubKey("Software\\MySoft");//在注册表项中创建子项
try
{
myReg2.SetValue("1", this.Location.X.ToString());//将窗体关闭位置的x坐标写入注册表
myReg2.SetValue("2", this.Location.Y.ToString());//将窗体关闭位置的y坐标写入注册表
}
catch { }
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: