saptechnique

Better late than never. - 郭富

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
 1//首先包含如下引用
 2
 3using Microsoft.Win32;
 4
 5//写注册表
 6
 7void SaveSettings()
 8
 9              {
10
11                     RegistryKey SoftwareKey=Registry.LocalMachine.OpenSubKey("Software",true);
12
13                     RegistryKey MovecontKey=SoftwareKey.CreateSubKey("Movecont");//建立
14
15                     RegistryKey SelfPlaceKey=MovecontKey.CreateSubKey("SelfPlace");//建立
16
17                     SelfPlaceKey.SetValue("BackColor",(object)BackColor.ToKnownColor());//
18
19                     SelfPlaceKey.SetValue("Red",(object)(int)BackColor.R);//
20
21                     SelfPlaceKey.SetValue("Green",(object)(int)BackColor.G);//绿
22
23                     SelfPlaceKey.SetValue("Blue",(object)(int)BackColor.B);//
24
25                     SelfPlaceKey.SetValue("Width",(object)Width);//
26
27                     SelfPlaceKey.SetValue("Height",(object)Height);//
28
29                     SelfPlaceKey.SetValue("X",(object)DesktopLocation.X);//左上角X坐标
30
31                     SelfPlaceKey.SetValue("Y",(object)DesktopLocation.Y);//左上角Y坐标
32
33                     SelfPlaceKey.SetValue("WindowState",(object)WindowState.ToString());//左上角Y坐标
34
35 
36
37              }

38
39//读注册表
40
41bool ReadSettings()
42
43              {
44
45                     RegistryKey SoftwareKey=Registry.LocalMachine.OpenSubKey("Software",true);
46
47                     RegistryKey MovecontKey=SoftwareKey.OpenSubKey("Movecont");//建立
48
49                     if(MovecontKey==null)
50
51                            return false;
52
53                     RegistryKey SelfPlaceKey=MovecontKey.OpenSubKey("SelfPlace");//建立
54
55                     if(SelfPlaceKey==null)
56
57                            return false;
58
59                     else
60
61                            this.listBoxMessages.Items.Add("成功打开注册表!");
62
63                     int Red=(int)SelfPlaceKey.GetValue("Red");
64
65                     int Green=(int)SelfPlaceKey.GetValue("Green");
66
67                     int Blue=(int)SelfPlaceKey.GetValue("Blue");
68
69                     BackColor=Color.FromArgb(Red,Green,Blue);
70
71                     this.listBoxMessages.Items.Add("Backcolor Name:"+BackColor.Name);
72
73                     int X=(int)SelfPlaceKey.GetValue("X");
74
75                     int Y=(int)SelfPlaceKey.GetValue("Y");
76
77                     DesktopLocation=new Point(X,Y);
78
79                     this.listBoxMessages.Items.Add("Location:"+DesktopLocation.ToString());
80
81                     Width=(int)SelfPlaceKey.GetValue("Width");
82
83                     Height=(int)SelfPlaceKey.GetValue("Height");
84
85                     this.listBoxMessages.Items.Add("Size:"+new Size(Width,Height).ToString());
86
87                     string Initstate=(string)SelfPlaceKey.GetValue("WindowState");
88
89                     //****枚举类型数据的Parse
90
91                     WindowState=(FormWindowState)FormWindowState.Parse(WindowState.GetType(),Initstate);
92
93                     return true;                   
94
95              }

96
posted on 2008-03-29 09:06  guofu  阅读(393)  评论(0编辑  收藏  举报