on 08-18-2011 6:50 AM
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
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
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.
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.
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?
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);
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
User | Count |
---|---|
89 | |
10 | |
9 | |
9 | |
9 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.