我想改变一个按钮的每个字母的颜色。怎么能成功呢? [英] I want to change the color of each letter of one button. How can make it?
问题描述
Button1.text =" VisualBasic.net"
Button1.text = "VisualBasic.net"
visual = red
visual = red
basic = blue
basic= blue
.net =黄色
推荐答案
visual = red
visual = red
basic = blue
basic= blue
.net = yellow
.net = yellow
使用text属性不能在普通控件中执行此操作。 而是将文本直接绘制到控件的绘制事件中提供的图形对象。 请参阅:
https://msdn.microsoft.com/en-us/library/21kdfbzs%28v=vs.110%29.aspx
https://msdn.microsoft.com/en-us/library/system.windows .forms.control.paint(v = vs.110).aspx
You can't do this in an ordinary control by using the text property. Instead, draw the text directly to the graphics object provided in the control's paint event. See:
https://msdn.microsoft.com/en-us/library/21kdfbzs%28v=vs.110%29.aspx
https://msdn.microsoft.com/en-us/library/system.windows.forms.control.paint(v=vs.110).aspx
创建一个具有所需颜色的新笔来绘制每一段文字。要正确定位绘图,您需要获取已绘制的字符串的大小,并添加到起始X位置。 请参阅:
https://msdn.microsoft .com / zh-CN / library / 6xe5hazb(v = vs.110).aspx
Create a new pen, with the required colour, to draw each piece of the text. To position the drawing correctly you need to get the size of the string already drawn, and addit to the starting X position. See:
https://msdn.microsoft.com/en-us/library/6xe5hazb(v=vs.110).aspx
或者,创建一个位图,从位图创建图形对象,绘制文本到位图,并使用该位图作为按钮图像属性。
https://msdn.microsoft.com/en-us/library/system.windows.forms.buttonbase.image(v = vs.110)的.aspx
Or, create a bitmap, create a graphics object from the bitmap, draw the text to the bitmap, and use that bitmap as the button Image property.
https://msdn.microsoft.com/en-us/library/system.windows.forms.buttonbase.image(v=vs.110).aspx
这篇关于我想改变一个按钮的每个字母的颜色。怎么能成功呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!