views:

4203

answers:

3

I am trying to format (bold or italics) only a portion of a textbox or Formula object (IFieldObject) in Crystal Reports for Visual Studio 2008.

I know how to make the entire field bold, but I want only a portion.

For example:

...blah blah blah May 12, 2009 blah blah blah...

Is this possible? I'm thinking there must be some sort of markup, but can't find any reference to it.

Thanks,

+4  A: 

You can do this by inserting HTML markup in the field (using a formula) and then displaying the new formula as a HTML field.

e.g. Here's a basic Syntax formula that takes a field and adds the bold tag around the text before the colon.

dim sTmp as string 
dim sLeft as string 
dim sRight as string 
dim sAll as string 

sTmp = {yourtable.yourfield}

sLeft = (split(sTmp,":"))(1)
sRight = (split(sTmp,":"))(2)

sAll = "<b>"+sLeft+":</b>"+sRight
formula = sAll

If you place this new formula into the report and then ...

  • Right Click the field and choose "Format Field"
  • Change Text Interpretation to HTML Text
  • Click 'OK'

There are Gotchas here. The original text is not HTML encoded, and I'm sure my example code does a simple one-line thing in about ten lines. Also, if your field has no colons in it, you'll force an error. However, it should give you the right idea.

seanyboy
This worked great, I added the <b></b> to the formula and then I changed the display (Format Object -> Paragraph -> Text Interpretation) to HTML Text. Thanks I was not aware of this option.
Nathan Koop
A: 

I don't know, if it is doable.

You could create a separate formula field for the value that you want to make bold & insert the formula field between other formula field, which will make it look like single sentence.

shahkalpesh
I think the problem with this answer is the dynamic sizing of the bolded field. Is there a way to have it dynamically sized and have the field behind it fit tight? (and perhaps span several lines)
Nathan Koop
A: 

Create a formula for the date part, then embed it into a text box, then you can format any way you like

This, unfortunately, was not possible as I only wanted the date to be bold not the entire text box. seanyboy's answer worked exactly as I wanted.
Nathan Koop