简体   繁体   中英

How to make text scroll in an edit box?

I am making a custom edit box using direct 2D and direct write. The painting stuff (box) is done by direct 2D. I take input from WM_CHAR message and append it to a string. This string gets written in the box. Now the problem is that whenever the text input exceeds the length of text box, it automatically scrolls down and now the text being input is not visible in text box. So how to scroll the text so that it always it in the text box.

这是显示编辑框的图像

这是显示问题的图像

I believe you've used the 'IDWriteTextFormat::SetTextAlignment' to make the text aligned to the center of the layout box. Similarly you can use the 'IDWriteTextFormat::SetParagraphAlignment' to control vertical alignment of the text.

But it can't do what you called "the text is always in the text box". You have to change font size to fit a static layout box. "Scrolling" can't help you here.

It all depends on what you want to do with it and how complex your control needs to be. If it's constraint to display a single line only, you can try to force DWRITE_WORD_WRAPPING_NO_WRAP wrapping mode. If you want it to be multiline and you only want to use single font, you can compute line height once, then on new line display next line instead of current; similar on VK_UP for example you can scroll one line back. The point is that with multiline control it's natural to expect it to display parts of your text in multiples of line height.

In any case you have to implement scrolling yourself, eg updating render target, and displaying only a part of it at a time. It's not a DirectWrite or D2D job to do that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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