cancel
Showing results for 
Search instead for 
Did you mean: 

How to set text object size correctly at runtime?

Former Member
0 Kudos

Hi,

I am using vs2010, c# to write a win form application.

I need to create text objects at runtime. The problem is that I could not find a way to know the correct size of the text object I should set. I tried use .net textbox to get the width and height, then multiply 15. The result is the height seems OK, but the width is too wide. I couldn't find something like CreateGraphics(); MeasureString() in crystal text object. Please help me for this problem.

Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Hello,

Click this link to get RAS samples, RAS is the report creation engine in CR for VS 2010.

http://wiki.sdn.sap.com/wiki/display/BOBJ/NETRASSDK+Samples#NETRASSDKSamples-Exporting%2FPrinting

Also, 1440 twips = 1 inch, not sure what the x 15 is for?

Thank you

Don

Former Member
0 Kudos

Hi Don,

Thank you for your help.

Following your instruction, I downloaded a sample "NET-CS2003 RAS-Managed BE115 Add Text-Field".

It demostrates how to add a text object at runtime. But it sets the text object as

boTextObject.Width = 1911;

boTextObject.Height = 226;

So if I assign a different text and font, how can I calculate the width and height?

0 Kudos

Hi Peter,

Nothing in CR that can do this, it's all Windows API's. I did a google search and found this article which may help:

http://msdn.microsoft.com/en-us/library/ff684173(v=vs.85).aspx

I don't have any sample code so I can't suggest anyway.

Thanks

Don

Former Member
0 Kudos

Hi Don,

Thank u very much.

I tried

TextBox tb = new TextBox();

tb.Font = new Font(new FontFamily(fontName), fontSize, fs, tb.Font.Unit);

Graphics g = tb.CreateGraphics();

int txtSize = (int)g.MeasureString(text, tb.Font).Width;

TextObject.Width = (int)Math.Ceiling(txtSize * 15); //15 = 1440 / 96 most screen is 96 dpi

But I found this sets the TextObject much more wider than neccessary.

0 Kudos

Hi Peter,

Have you tried 120 DPI? CR calculates the size using the same type of functions you are using so there must some a constant that works better...

Thanks

Don

Former Member
0 Kudos

Hi Don,

Thank you for your help.

I found what is the real problem. The box width in crystal report is calculated correctly, but the text in the same font is squashed compared with the width of text in the textbox in the VS2010 win form.

The font I used is Microsoft sans serif, bold, size 12.

As DPI, I used the api to determine what is actural dpi of the screen.

0 Kudos

Hi Peter,

Search for "forceLargeFonts" and you'll find a registry key that needs to be set. Or use Process Monitor, it will show you the key we are looking for and where to create it.

Don

Former Member
0 Kudos

Hi Don,

Thank you very much.

I searched google and your web page. But I am not able to find any answer to fix the problem for the crystal reports for Visual Studio 2010. Also I don't know any thing about the Process Monitor. Is Process Monitor available in crystal reports for Visual Studio 2010?

Would you please provider me a link to fix for my version of CR?

0 Kudos

Use Bing or Google to search for ProcessMonitor, it belongs to Microsoft...

Search in here also on force large fonts and you'll find the key...

Thanks

Don

Former Member
0 Kudos

Hi Don,

Thank u very much.

Following your instruction, I downloaded the Process Monitor. Run it and saved a log file. But I could not find force large font, force larger font, forcelargefont, forcelargerfont or UsePrecisePositioningForText in the log.

In my program, I wrote

rptDoc.ExportToStream(ExportFormatType.CrystalReport);

0 Kudos

Hi Peter,

Thanks for testing, We tested it here also and it does appear we don't check, there is a Flag in the Merge Modules to create the key, you have to set it to "1", but the engine doesn't look for it. Sorry I thought we had this fixed.

We'll have to create a bug track and get it into SP3, SP 2 is now closed.

Thanks again

Don

Former Member
0 Kudos

Hi Don,

Thank you very much for your serious attitude to my question.

Answers (0)