文字为彩色 [英] Text to color

查看:77
本文介绍了文字为彩色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,
我想从给定的文本中选择一种颜色.假设用户在文本框中输入颜色名称.我想要的是根据在文本框中键入的颜色来更改表单颜色.说myform.backgroundcolor =?(我应该输入什么才能将文本转换为颜色)

希望你能得到.不需要使用colordialog.
谢谢.
关于

解决方案

使用

 Color myColor = Color.FromName(textBox1.Text);
如果(!(myColor.A ==  0 && myColor.R ==  0 && myColor.G ==  0 &&
    myColor.B ==  0 ))
{
   .BackColor= myColor;
} 



如果颜色不是预定义的名称,则它将对所有ARGB元素返回0.因此,您需要提供一个下拉列表.


如果在文本框中输入了KnownColor,则实际上可以进行转换.

有关已知颜色的列表,请参见此处.


Hi Folks,
I want to make a color from given text. say the user types in the color name in a text box. what I want is to change the form color according to the color typed in the text box. Say myform.backgroundcolor=?(what should I type in to convert text to the color )

Hope you are getting. don''t need to use colordialog.
Thank you.
Regards

解决方案

use

Color myColor = Color.FromName(textBox1.Text);
if (!(myColor.A == 0 && myColor.R == 0 && myColor.G == 0 &&
    myColor.B == 0))
{
   this.BackColor = myColor;
}



If the color is not a predefined name, then it will return 0 to all of the ARGB elements.


There is plainly no API that cN magically decipher any terminology possible for any color. So, a drop down is what you need.


If a KnownColor is entered in a text box, you can actually do a conversion.

See here for a list of know colors.


这篇关于文字为彩色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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