zoukankan
html css js c++ java
读写注册表来保存窗体当前设置
using
System;
using
System.Drawing;
using
System.Collections;
using
System.ComponentModel;
using
System.Windows.Forms;
using
Microsoft.Win32;
namespace
RegiestryManager
{
/**/
///
<summary>
///
Form2 的摘要说明。
///
</summary>
public
class
Form2 : System.Windows.Forms.Form
{
private
System.Windows.Forms.Button button1;
private
System.Windows.Forms.ColorDialog chooseColorDialog;
/**/
///
<summary>
///
必需的设计器变量。
///
</summary>
private
System.ComponentModel.Container components
=
null
;
public
Form2()
{
//
//
Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
//
TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
LoadFormPropertySet();
}
/**/
///
<summary>
///
清理所有正在使用的资源。
///
</summary>
protected
override
void
Dispose(
bool
disposing )
{
if
( disposing )
{
if
(components
!=
null
)
{
components.Dispose();
}
}
base
.Dispose( disposing );
}
Windows 窗体设计器生成的代码
#region
Windows 窗体设计器生成的代码
/**/
///
<summary>
///
设计器支持所需的方法 - 不要使用代码编辑器修改
///
此方法的内容。
///
</summary>
private
void
InitializeComponent()
{
this
.button1
=
new
System.Windows.Forms.Button();
this
.chooseColorDialog
=
new
System.Windows.Forms.ColorDialog();
this
.SuspendLayout();
//
//
button1
//
this
.button1.Location
=
new
System.Drawing.Point(
352
,
112
);
this
.button1.Name
=
"
button1
"
;
this
.button1.TabIndex
=
0
;
this
.button1.Text
=
"
button1
"
;
this
.button1.Click
+=
new
System.EventHandler(
this
.button1_Click);
//
//
Form2
//
this
.AutoScaleBaseSize
=
new
System.Drawing.Size(
6
,
14
);
this
.ClientSize
=
new
System.Drawing.Size(
480
,
326
);
this
.Controls.Add(
this
.button1);
this
.Name
=
"
Form2
"
;
this
.Text
=
"
Form2
"
;
this
.Closing
+=
new
System.ComponentModel.CancelEventHandler(
this
.Form2_Closing);
this
.Load
+=
new
System.EventHandler(
this
.Form2_Load);
this
.ResumeLayout(
false
);
}
#endregion
private
void
Form2_Load(
object
sender, System.EventArgs e)
{
}
//
在窗体启动时加载上次设置
private
bool
LoadFormPropertySet()
{
try
{
if
(ReadSettings(
this
.Text)
==
false
)
return
false
;
StartPosition
=
FormStartPosition.Manual;
//
设定当前窗体的起始位置为原始起始位置
}
catch
{
return
false
;
}
return
true
;
}
/**/
///
/在窗体关闭时保存本次设置
private
bool
SaveFormPropertySet()
{
try
{
SaveSettings(
this
.Text );
}
catch
{
return
false
;
}
return
true
;
}
private
void
SaveSettings(
string
FormName)
{
RegistryKey softwareKey
=
Registry.LocalMachine.OpenSubKey(
"
Software
"
,
true
);
RegistryKey frjKey
=
softwareKey.CreateSubKey(FormName) ;
RegistryKey selfPlacingWindowKey
=
frjKey.CreateSubKey(
"
SelfPlacingWindow
"
) ;
selfPlacingWindowKey.SetValue(
"
BackColor
"
,(
object
)BackColor.ToKnownColor() ) ;
selfPlacingWindowKey.SetValue(
"
Red
"
,(
object
)(
int
)BackColor.R );
selfPlacingWindowKey.SetValue(
"
Green
"
,(
object
)(
int
)BackColor.G );
selfPlacingWindowKey.SetValue(
"
Blue
"
,(
object
)(
int
)BackColor.B );
selfPlacingWindowKey.SetValue(
"
Width
"
,(
object
)Width);
selfPlacingWindowKey.SetValue(
"
Height
"
,(
object
)Height);
selfPlacingWindowKey.SetValue(
"
X
"
,(
object
)DesktopLocation.X );
selfPlacingWindowKey.SetValue(
"
Y
"
,(
object
)DesktopLocation.Y);
selfPlacingWindowKey.SetValue(
"
WindowState
"
,(
object
)WindowState.ToString() );
}
private
bool
ReadSettings(
string
FormName)
{
RegistryKey softwareKey
=
Registry.LocalMachine.OpenSubKey(
"
Software
"
,
true
);
RegistryKey frjKey
=
softwareKey.OpenSubKey(FormName) ;
if
(frjKey
==
null
)
return
false
;
RegistryKey selfPlacingWindowKey
=
frjKey.OpenSubKey (
"
SelfPlacingWindow
"
) ;
if
(selfPlacingWindowKey
==
null
)
return
false
;
int
redComponent
=
(
int
)selfPlacingWindowKey.GetValue(
"
Red
"
) ;
int
greenComponent
=
(
int
)selfPlacingWindowKey.GetValue(
"
Green
"
) ;
int
blueComponent
=
(
int
)selfPlacingWindowKey.GetValue(
"
Blue
"
) ;
this
.BackColor
=
Color.FromArgb (redComponent,greenComponent,blueComponent);
int
X
=
(
int
)selfPlacingWindowKey.GetValue(
"
X
"
) ;
int
Y
=
(
int
)selfPlacingWindowKey.GetValue(
"
Y
"
) ;
this
.DesktopLocation
=
new
Point(X,Y) ;
this
.Height
=
(
int
)selfPlacingWindowKey.GetValue(
"
Height
"
) ;
this
.Width
=
(
int
)selfPlacingWindowKey.GetValue(
"
Width
"
) ;
string
initialWindowState
=
(
string
)selfPlacingWindowKey.GetValue(
"
WindowState
"
) ;
this
.WindowState
=
checked
((FormWindowState)FormWindowState.Parse(WindowState.GetType(), initialWindowState));
return
true
;
}
private
void
button1_Click(
object
sender, System.EventArgs e)
{
if
(
this
.chooseColorDialog.ShowDialog()
==
DialogResult.OK )
BackColor
=
chooseColorDialog.Color;
}
private
void
Form2_Closing(
object
sender, System.ComponentModel.CancelEventArgs e)
{
SaveFormPropertySet();
}
}
}
查看全文
相关阅读:
C#线程类Thread初步
无限级分类存储过程版
C#多线程编程实例实战
数据库里阻塞和死锁情况 看那里死锁的存储过程
预防按钮的多次点击 恶意刷新
.net2.0文件压缩/解压缩
HttpHandler和HttpModule入门
反射,枚举,绑定下拉框
在C#里关于定时器类
判断上传的图片文件格式是否合法不是用后缀做的判断
原文地址:https://www.cnblogs.com/furenjun/p/387596.html
最新文章
PHP 大小写转换
关于PHP中的unset
【原译】汇编编程之:Hello World!详解
Menu控件+SQLServer实现动态多级菜单
【原译】简单的Malloc实现
windows下配置gvim的备份文件到统一目录
Win7下添加和取消右键获取管理员权限的方法
希尔排序
Ural 1014 Product of Digits NYOJ 270 数的分解 解题报告
C++参数传递类型的选择
热门文章
mysql中删除字符串或字段中空格函数
css div自适应宽度实例
javascript中匿名函数分析详解
php中时间相差8小时的多种解决办法
cannot restore segment prot after reloc: Permission denied解决办法
sql中取字符串中的数字语句
JavaScript 基础入门篇(一)
asp.net bind()和eval()的区别
mysql 中取字符串中的数字sql语句
sql截取字段最后以特定字符隔开的内容语句
Copyright © 2011-2022 走看看