简体   繁体   English

有没有更好的方法在CStatic控件中的第一个单词下划线?

[英]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字符数组lineDatabool的数组linesToUnderline lineData stores just text. lineData仅存储文本。 linesToUnderline stores a true or a false for each line in lineData . linesToUnderlinelineData每一行存储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: 所以目前,我正在考虑做的是:

  1. If linesToUnderline[i] = false, go to step 4. 如果linesToUnderline[i] = linesToUnderline[i] ,请转到步骤4。
  2. Get the first word from lineData , put it in a static control, set that control's font to underlined. lineData获取第一个单词,将其放在静态控件中,将该控件的字体设置为带下划线的字体。
  3. Remove the first word from lineData . lineData删除第一个单词。
  4. Increment starting X position by lineData 's pixel length. lineData的像素长度递增X起始位置。
  5. Put lineData in a static control starting at a position X, Y. lineData放在从X,Y位置开始的静态控件中。
  6. If i < numLines go to step 1. 如果i < numLines请转到步骤1。
  7. Stop. 停止。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM