| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 399 人关注过本帖
标题:关与修改注册表问题
只看楼主 加入收藏
casualhewo
Rank: 1
等 级:新手上路
帖 子:267
专家分:0
注 册:2006-6-13
收藏
 问题点数:0 回复次数:0 
关与修改注册表问题

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;

namespace SelfPlacingWindow
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
button1.Click += new EventHandler(button1_Click);
try
{
if (ReadSettings() == false)
{
listBox1.Items.Add("No information in registry");
}
else
{
listBox1.Items.Add("Information read in from registry");
}

}
catch(Exception e)
{
listBox1.Items.Add("A problem occurred reading in data form registry");
listBox1.Items.Add(e.Message);
}
}
ColorDialog Cdialog = new ColorDialog();

private void button1_Click(object sender, EventArgs e)
{

if (Cdialog.ShowDialog ()==DialogResult.OK)
{
BackColor = Cdialog.Color;
return;
}
}
private void SaveSettings()
{
RegistryKey SoftwareKey = Registry.LocalMachine.OpenSubKey("Software", true);
RegistryKey WroxKey = SoftwareKey.CreateSubKey("WroxPress");
RegistryKey SelfPlacingWindowKey = WroxKey.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()
{
RegistryKey SoftwareKey = Registry.LocalMachine.OpenSubKey("Software");
RegistryKey WroxKey = SoftwareKey.OpenSubKey("WroxPress");
if(WroxKey == null)
return false;
RegistryKey SelfPlacingWindowKey = WroxKey.OpenSubKey("SelfPlacingWindow");
if (SelfPlacingWindowKey == null)
return false;
else
listBox1.Items.Add("Successfully opened key" + SelfPlacingWindowKey.ToString());
int RedComponent = (int)SelfPlacingWindowKey.GetValue("Red");
int GreenComponent = (int)SelfPlacingWindowKey.GetValue ("Green");
int BlueComponent = (int)SelfPlacingWindowKey.GetValue("Blue");
BackColor = Color.FromArgb(RedComponent ,GreenComponent ,BlueComponent);
listBox1.Items.Add("Background color:"+ BackColor.Name);
int X = (int)SelfPlacingWindowKey.GetValue("X");
int Y = (int)SelfPlacingWindowKey.GetValue("Y");
DesktopLocation = new Point(X,Y );
listBox1.Items.Add("Desktop lacation:" + DesktopLocation.ToString ());
Height = (int)SelfPlacingWindowKey.GetValue("Height");
Width = (int)SelfPlacingWindowKey.GetValue("Width");
listBox1.Items.Add("Size:"+ new Size (Height,Width).ToString ());
string InitialWindowState = (string)SelfPlacingWindowKey.GetValue("WindowState");
listBox1.Items.Add("Window State:"+InitialWindowState);
// WindowState = (FormWindowState)FormWindowState.Parse(WindowState.GetType (),InitialWindowState);
return true;


}
}
}
记住上面还有一句在写在dispose()方法里.就是SaveSettings()方法.
书上抄的原码:为什么再次启动Form的位置不能固定啊!颜色和大小都能固定.这是什么原因啊!
上面红色的部分在2005上不能用.formwindowstate没有parse的方法.红色部分如何修改.

搜索更多相关主题的帖子: 注册表 
2007-02-03 23:11
快速回复:关与修改注册表问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.039324 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved