Jump to content

SetTextStyle Demystified

Recommended Posts

Has anyone ever tried to set the TextStyle of a text object with:

Procedure SetTextStyle (objectHd:HANDLE; Start:INTEGER; Count:INTEGER; Style :INTEGER); ?

I had tried to use it for months with varying results:

TxtStyle := GetTextStyle(TxtHnd, 0); { save text style }{ change things up here }SetTextStyle(TxtHnd, 0, strLength, TxtStyle); { reset text style }

Note: In the above example, the whole text block has the same formatting as the first character. If individual characters have separate formatting, then additional code will be needed.

The documentation appears straightforward, but the results were anything but. I finally figured out what was missing from the written word. Just as the menu commands in the TEXT / STYLE submenu work, so does the VS command. The menu commands TOGGLE the text attributes. If some characters in a text block are BOLD and some are not, then with the whole text block selected (not a range of characters), selecting the Text / Style / Bold submenu item changes the BOLD characters to PLAIN, and the PLAIN characters to BOLD. To get all BOLD characters, you must first clear all formatting by selecting PLAIN and then select the BOLD option.

Adding one more SetTextStyle statement makes the next SetTextStyle command work the way the documentation would lend you to believe it should have worked in the first place.

TxtStyle := GetTextStyle(TxtHnd, 0); { save text style }{ change things up here }SetTextStyle(TxtHnd, 0, strLength, 0); { clear style formatting }SetTextStyle(TxtHnd, 0, strLength, TxtStyle); { set new style formatting }

This even works with multiple format styles selected, like BOLD & ITALIC.


Link to comment
  • 3 weeks later...

Hi Ramond,

Thanks for posting this. This kind of revelation saves each of us the time it took for you to figure it out. It should be in the documentation.

I think there should be a programmers version of the command reference on the web somewhere where we could collectively post notes on usage, examples, etc. searchable and updated with the latest additions periodically.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...