如何使用面板上的图形类绘制多色文本? [英] How can I draw multi-colored text using graphics class on panel ?

查看:87
本文介绍了如何使用面板上的图形类绘制多色文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在面板上绘制以下文字

示例文字

我该怎么办?



我尝试过:



 Dim path As GraphicsPath = New GraphicsPath()

Dim emSize As Single = 120
path.AddString(示例文本, font.FontFamily,CInt(font.Style),emSize,rect,format)

g.FillPath(Brushes.Yellow,path)
g.DrawPath(Pens.Black,path)

解决方案

为此,您需要使用几种不同的FillPath和DrawPath命令组合,每种组合都有不同的画笔集。这将是非常混乱并且很难实现,因为您需要将每个需要在颜色集中的连续单词块分开,绘制它,然后使用Graphics.MeasureString或GraphicsPath.GetBounds(可能是后者)来找出它占用了多少空间,所以你可以使用它作为下一个文本块的偏移量的一部分。



可能会有相当多的迭代次数在这个发展过程中继续;我第一次尝试它时,我不希望它看起来很完美,所以我怀疑你应该这样做! :笑:

I want to draw the following text on panel
sample text
how can i do that?

What I have tried:

Dim path As GraphicsPath = New GraphicsPath()

       Dim emSize As Single = 120
       path.AddString("sample text", font.FontFamily, CInt(font.Style), emSize, rect, format)

       g.FillPath(Brushes.Yellow, path)
       g.DrawPath(Pens.Black, path)

解决方案

To do that you would need to use several different FillPath and DrawPath command combinations, each with a different brush set. That's going to be very messy and quite difficult to implement as you will need to separate out each block of contiguous words that needs to be in a colour set, draw it, then use Graphics.MeasureString or GraphicsPath.GetBounds (probably the later) to find out how much space it took up, so you can use that as part of the offset to the next text block.

There will probably be a fair amount of iteration going on during this development; I wouldn't expect it to look perfect the first time I tried it, so I doubt you should either! :laugh:


这篇关于如何使用面板上的图形类绘制多色文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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