如何从注册表中读取颜色? [英] How to read a color from registry?

查看:129
本文介绍了如何从注册表中读取颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将颜色对象保存到注册表会将其值设置为类似

颜色[红色]或颜色[A = 255,R = 123,G] = 234,B = 231]",

但如何将其重新放回Color对象???


将其转换为Color只会导致一个例外。


-

使用M2,Opera的革命性电子邮件客户端: http://www.opera.com/m2/

Saving a color object to registry will set it''s value to something like
"Color [Red]", or "Color [A=255, R=123, G=234, B=231]",
but how do I get this back into a Color object???

Casting it to Color only causes an exception.

--
Using M2, Opera''s revolutionary e-mail client: http://www.opera.com/m2/

推荐答案

可以显示一些代码吗?


-

Carsten Thomsen

使用VS .NET进行企业开发,UML和MSF
http:// www .apress.com / book / bookDisplay.html?bID = 105

" Morten Wennevik" <莫************ @ hotmail.com>写在消息中

news:oprxq49ly0hntkfz @ localhost ...

将颜色对象保存到注册表会将其值设置为类似

颜色[红色]或颜色[A = 255,R = 123,G = 234,B = 231],

但是如何将其重新置于一个颜色对象???


将它转换为Color只会导致异常。


-

使用M2,Opera的革命性电子邮件客户端: http://www.opera.com / m2 /
Can you show some code, please?

--
Carsten Thomsen
Enterprise Development with VS .NET, UML, and MSF
http://www.apress.com/book/bookDisplay.html?bID=105
"Morten Wennevik" <Mo************@hotmail.com> wrote in message
news:oprxq49ly0hntkfz@localhost...
Saving a color object to registry will set it''s value to something like
"Color [Red]", or "Color [A=255, R=123, G=234, B=231]",
but how do I get this back into a Color object???

Casting it to Color only causes an exception.

--
Using M2, Opera''s revolutionary e-mail client: http://www.opera.com/m2/


在HKEY_Current_User \Software \ ColorTest中创建一个注册表条目


Color testColor = Color.FromArgb(123,234,75);

RegistryKey regKey =

Registry.CurrentUser.CreateSubKey(" Software \\ Color Test");

regKey.SetValue(" Color",testColor);

regKey.Close();


要阅读它我想要的使用像
这样的东西/>
RegistryKey colorKey =

Registry.CurrentUser.OpenSubKey(" Software \\ColorTe st");

颜色regColor =(颜色)regKey .GetValue(QUOT;颜色"); //这不起作用

colorKey.Close();


我可以通过将颜色转换为int并从
int,但我更喜欢在注册表中保持颜色可读。


-

使用M2,Opera的革命性电子邮件客户端: http://www.opera.com/m2/
To make a registry entry in HKEY_Current_User\Software\ColorTest

Color testColor = Color.FromArgb(123, 234, 75);
RegistryKey regKey =
Registry.CurrentUser.CreateSubKey("Software\\Color Test");
regKey.SetValue("Color", testColor);
regKey.Close();

To read it I would want to use something like

RegistryKey colorKey =
Registry.CurrentUser.OpenSubKey("Software\\ColorTe st");
Color regColor = (Color)regKey.GetValue("Color"); // this does not work
colorKey.Close();

I can do it by translating the color to int and creating a new color from
int, but I would prefer to keep the color readable in registry.

--
Using M2, Opera''s revolutionary e-mail client: http://www.opera.com/m2/


----- BEGIN PGP签名消息-----

哈希:SHA1


啊,那是因为你将ToString()方法的结果保存到

注册表中。不幸的是,没有简单的方法将它转换回Color

~除了检查字符串之外 - 绝对不能把它转换为

颜色因为它是一个字符串!


最好将调用ToArgb()的结果保存到注册表中。当

你加载int值并需要从

实例化一个Color对象时,你可以说:


颜色col = Color.FromArgb(<把注册表中的int放在这里>);


Morten Wennevik写道:

|将颜色对象保存到注册表会将其值设置为类似

|的值Color [Red]或Color [A = 255,R = 123,G = 234,B = 231],

|但是如何将它重新变成Color对象???

|

|将它投射到Color只会导致异常。

|

- -

Ray Hsieh(Ray Djajadinata)[SCJP,SCWCD]

射线下划线使用ynet dot com

----- BEGIN PGP SIGNATURE -----

版本:GnuPG v1.2.3(MingW32 )

评论:将GnuPG与Thunderbird一起使用 - http://enigmail.mozdev。组织


iD8DBQE / nnFPwEwccQ4rWPgRAiw4AJ9FYtAbDAsnnlk1wN5AH6QNldySA CfedAF

1OuxNwXHBgtVDRAZ55VQx7M =

= bG0X

- ----结束PGP签名-----

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Ah, that''s because you''re saving the result of ToString() method to the
registry. Unfortunately, there''s no easy way to convert it back to Color
~ other than examining the string--and definitely you can''t cast it to
Color because it''s a string!

It''s better to save the result of calling ToArgb() to the registry. When
you load the int value back and need to instantiate a Color object from
that, you can just say:

Color col = Color.FromArgb(<put the int from the Registry here>);

Morten Wennevik wrote:
| Saving a color object to registry will set it''s value to something like
| "Color [Red]", or "Color [A=255, R=123, G=234, B=231]",
| but how do I get this back into a Color object???
|
| Casting it to Color only causes an exception.
|
- --
Ray Hsieh (Ray Djajadinata) [SCJP, SCWCD]
ray underscore usenet at yahoo dot com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQE/nnFPwEwccQ4rWPgRAiw4AJ9FYtAbDAsnn2lkNwv5XH6QNldySA CfedAF
1OuxNwXHBgtVDRAZ55VQx7M=
=bG0X
-----END PGP SIGNATURE-----


这篇关于如何从注册表中读取颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆