I’m trying to do something that seems like it ought to be easy, but I’ve found no (obvious) simple solution.
As a program is running, interim results and comments are added to a string (call it StringCum),
that - at the discretion of the user - may be shown via a call to MessageDialog[StringCum,…]. So far, so good.
What I’d like to do, however, is periodically highlight certain text. For example, if a special event, Event1, occurs,
I’d like that portion of the cumulative string to be highlighted (say, as FontColor->Red). The command,
MessageDialog[ StringCum <> Style[“Event1 has occurred”, FontColor → Red]] highlights the text but (1) print “<>” as though it was itself a string, and (2) does not alloow me to concatenate any further strings at some later point; i.e., I’d like to define StringCum =StringCum <>Style[“Event1 has occurred”, FontColor → Red]], I get an error. And if I try defining a string: StringCum =StringCum <>ToString[Style[“Event1 has occurred”, FontColor → Red]]], everything works except that the color highlighting disappears.
In short, I’d like to highlight selected parts of a string that is being displayed via MessageDialog,
Anything anyone can suggest?
Thanks! (first time posting here…I’ve done a search on what I thought were similar issues, but could not find a match).
importantMsg = Style["the oven is getting hot!", Red];
message = Row[{"Would like to say that ", importantMsg, " and needs cooling"}];
MessageDialog[message]
That’s already a help, but with still this lingering issue…as the main program keeps running, it keeps track of a cumulative message string (continually updated): i.e., if the current message (to be printed via MessageDialog) is your message = Row[{"Would like to say that “, importantMsg, " and needs cooling”}];, I still need - at some later point - to have something like message <> “here is another string (possibly with its own highlighting)” to be available to MessageDialog. But, since message is now a Row[…], the concatenation can’t go through since it’s no longer a string.
Hope that makes sense, and my problem is clear. Essentially I need what your great suggestion does for this one message, but I need to be able to keep concatenating strings to this (some of which may have highlights, some not).
But, since message is now a Row[…], the concatenation can’t go
through since it’s no longer a string
You can try Join, like this, to see if it works for you
nextMessage = Style["the oven is getting hot!", Red];
message = Row[{"Would like to say that ", importantMsg, " and needs cooling"}];
MessageDialog[message];