使用C#windows应用程序为变量值设置颜色 [英] set color for an variable value using C# windows applicati

查看:345
本文介绍了使用C#windows应用程序为变量值设置颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用C#windows应用程序为变量值指定颜色。



为例。,int i = 5;



将答案放在toolstripbutton中。喜欢Notification(5)。我只想改变'5'的颜色。并非所有人。我可以用b $ bs bs,有人可以帮我这个...

解决方案

你可以,

但是唯一的问题是toolstripbutton作为一个控件工作。

如果你想改变显示'Notification(5)'的文本,其中5是红色,你必须找到一种区分文本的方法,

因为,如果更改了toolstripbutton的颜色,则文本本身就是一个单词,整个文本也是如此,

你必须为此处理两个文本。 / blockquote>

没有标准的方法可以做到这一点:你必须自己处理按钮的Paint事件,然后用多种颜色将文本绘制到它上面 - 这听起来不像听起来那么简单,因为你需要使用MeasureString三次来获得每个部分的大小(Notifications(是一个,5是第二个,而)是第三个)然后当你拥有它的复合时将所有文本居中长度)。



我可能会作弊,而c创建十个左右的图像:1-9和++超过十个,而不是在按钮上添加文字。


is it possible to assign a color for an variable value using C# windows application.

for an example., int i = 5;

place the answer in toolstripbutton. like "Notification(5)". I only want to change the color for '5'. Not for all. I
s it possible, can anyone help me with this...

解决方案

You can,
But only problem is toolstripbutton works as a single control.
If you want to change the text displaying 'Notification (5)' where 5 is suppose red in color, you have to find a way to differentiate the text,
Since, the text is one word itself if color of toolstripbutton is changed, so does the whole text,
You have to work around with two texts for this.


There is no standard way to do this: you would have to handle the Paint event for the button yourself and draw the text onto it in multiple colours - which isn't as trivial as it sounds, because you need to use MeasureString three times to get each part size ("Notifications(" is one, "5" is the second, and ")" is the third) then centre all of the text when you have it's "composite" length).

I'd probably cheat, and create a ten or so images: 1-9 and "++" for more than ten instead of faffing with text on my button.


这篇关于使用C#windows应用程序为变量值设置颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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