[英]Is there a better way to underline the first word in a CStatic control?
I have a 2D character array lineData
and an array of bool
s, linesToUnderline
. 我有一个2D字符数组
lineData
和bool
的数组linesToUnderline
。 lineData
stores just text. lineData
仅存储文本。 linesToUnderline
stores a true or a false for each line in lineData
. linesToUnderline
为lineData
每一行存储true或false。 Each line in lineData
is being put in a static control (which is created dynamically) in a certain fashion to display to the user. lineData
每一行都以lineData
方式置于静态控件(动态创建)中,以显示给用户。
Now if linesToUnderline[i]
= true (for 0 <= i < numLines
), I need to display the line with only the first word underlined and the rest of the text normally. 现在,如果
linesToUnderline[i]
= true(对于0 <= i < numLines
),我需要显示仅用下划线标出第一个单词 ,而其余文本正常显示的行。
What I'm talking about looks like: 我在说什么看起来像:
So currently, what I'm thinking of doing: 所以目前,我正在考虑做的是:
linesToUnderline[i]
= false, go to step 4. linesToUnderline[i]
= linesToUnderline[i]
,请转到步骤4。 lineData
, put it in a static control, set that control's font to underlined. lineData
获取第一个单词,将其放在静态控件中,将该控件的字体设置为带下划线的字体。 lineData
. lineData
删除第一个单词。 lineData
's pixel length. lineData
的像素长度递增X起始位置。 lineData
in a static control starting at a position X, Y. lineData
放在从X,Y位置开始的静态控件中。 i
< numLines
go to step 1. i
< numLines
请转到步骤1。 What do you think of my method? 您如何看待我的方法? I feel that there must be a better way to do this.
我认为必须有更好的方法来做到这一点。 If there is, could someone help me out?
如果有,有人可以帮我吗?
Your proposed method will not work. 您建议的方法将不起作用。 The control uses only one font at a time (for all its text) and it does not provide a way to append text at X,Y.
控件一次仅使用一种字体(用于其所有文本),并且没有提供在X,Y处附加文本的方法。
You must subclass the control and paint the text yourself in WM_PAINT. 您必须将控件子类化,并在WM_PAINT中自己绘制文本。 Your paint code can provide the necessary features.
您的绘画代码可以提供必要的功能。
This code project article implements a hyperlink control by subclassing a static control. 此代码项目文章通过将静态控件子类化来实现超链接控件。 You can use it as a base for doing custom underlining.
您可以将其用作进行自定义下划线的基础。 All you have to do is simplify the code.
您要做的就是简化代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.