Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi All,
I want to print a subscript text(like "HBA IC") in PrintDocument print page.
I searched on Google but I couldn't find any solution..
So, I write this code:
C#
Font ftNormal = new System.Drawing.Font("Arial", 12);
 e.Graphics.DrawString("HBA IC",ftNormal,Brushes.Black,20,50);

I have no idea about this, is there need to calculate the text size or somthing else to print that text as a subscript?

Thanks in advanced.

Regards
Jayanta.
Posted
Comments
BillWoodruff 22-Dec-15 0:51am    
This (C++) article might assist you: "Using Subscripts and Superscripts When Showing Text in the Device Context:" http://www.codeproject.com/Articles/12660/Using-Subscripts-and-Superscripts-When-Showing-Tex" target="_blank" title="New Window">^].

Have you looked into using Unicode Escape formatting to produce subscript ... I'm not sure if that works with PrintDocument.
JayantaChatterjee 22-Dec-15 1:31am    
Thank for Suggestion..
PrintDocument support the Unicode Characters. now I'm finding the IC as a subscript character from the unicode character list....
thanks a lotttt...

I solve my problem with the Unicode which suggested by @BillWoodruff..

I found the Unicode Characters from this site: Unicode Characters List[^], then copy the unicode and paste it to in the code.

My code become:
C#
e.Graphics.DrawString("HBA ɪϲ ", ftNormal, Brushes.Black, 20, 50);


thanks to Sir,
Quote:
@BillWoodruff
 
Share this answer
 
Comments
BillWoodruff 22-Dec-15 3:52am    
good for you ! I think I'll change my comment to a solution :)
JayantaChatterjee 24-Dec-15 0:11am    
Thank You Sir...
This (C++) article might assist you: "Using Subscripts and Superscripts When Showing Text in the Device Context:" [^].

Have you looked into using Unicode Escape formatting to produce subscript ... I'm not sure if that works with PrintDocument.

If you do end up using a RichTextBox, see this MSDN article in addition to the link Sergey cites: [^].

If you find a good solution, I'd like to suggest you post it here as a 'Tip/Trick.'
 
Share this answer
 
I suggest to implement the content with such kind of formatting (and a lot more) using RTF. This old MSDN article explains how to do that: https://support.microsoft.com/en-us/kb/812425[^].

Moreover, there is a good way to render RichTextBox content as HTML provided in this CodeProject article: A Professional HTML Renderer You Will Use[^].

Indeed, formatting control with RichTextBox quite awkward. HTML is much easier. All the RTF formatting work is already done for you.

—SA
 
Share this answer
 
Comments
JayantaChatterjee 22-Dec-15 1:05am    
HTML Renderer is good. but Sir, I already developed my "Final year" project with PrintDocument control. I'm stuck in this part. if I change the printDocument, then I need to change approx. three PrintDocument controls code.
So, is there any way to do this with PrintDocument?

Thanks for the suggestion..
Sergey Alexandrovich Kryukov 22-Dec-15 1:37am    
Of course you can. First link explain how to do that.

What's the problem? You don't want to use RTF (through HTML or not)? Them you would have to invent something similar, perhaps more specialized and, due to this specialization, something simpler. But are you sure you want it? You will simply need to reduce fort and and shift the base line. There is one problem which is very hard to solve: hinting. To replace one string with two, you will need to precisely position them. This is nearly impossible to do accurately, because all methods of calculation of rendered text width are inaccurate. My prediction is: you won't be able to solve this problem.

So, I'm afraid you won't have any other choice. You will have to choose between "too much change in data" and "impossible". The final decision is yours.

Now, I answered your question comprehensively and suggest you accept the answer formally.

—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900