473,748 Members | 2,161 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

.NET Graphics.DrawSt ring with Unicode characters

vekipeki
229 Recognized Expert New Member
I am having a problem with basic drawing of unicode characters in Windows 2000 and XP.

I have written a simplest possible C# WinForms program to test it (just create a new Windows Forms C# application and add a Paint event handler):

Expand|Select|Wrap|Line Numbers
  1. public partial class Form1 : Form
  2. {
  3.     public Form1()
  4.     {
  5.         InitializeComponent();
  6.         this.Paint += new PaintEventHandler(Form1_Paint);
  7.     }
  8.  
  9.     void Form1_Paint(object sender, PaintEventArgs e)
  10.     {
  11.         Font f = new Font("Tahoma", 12); // this is used just to get a larger font
  12.  
  13.         // try drawing with DrawString
  14.         e.Graphics.DrawString("Test \u2153", f, SystemBrushes.ControlText, new PointF(10, 50));
  15.  
  16.         // try drawing with DrawText
  17.         TextRenderer.DrawText(e.Graphics, "Test \u2153", f, new Rectangle(10, 10, 50, 50), SystemColors.ControlText);
  18.     }
  19. }
  20.  
In Windows Vista, the unicode character (U2153, representing "1/3" in a single character) is drawn twice, but in Windows XP or 2000, it is not drawn in any case.

So, the question is: how to draw a unicode string in XP?

[EDIT:] I just found out something, but decided to add this post anyway: the main problem is - Windows XP Tahoma font simply does not have these characters! When you try to insert this unicode symbol in MS Word using Tahoma font, it is omitted from the list (http://zero2180.net/2008/01/tahoma/).

I usually use SystemFonts.Mes sageBoxFont to get the default system font (returns "Tahoma" for XP and 2000, "Segoe" for Vista).

So what font should I then use for unicode?
Sep 30 '08 #1
6 10712
Plater
7,872 Recognized Expert Expert
Find one that supports the characters you want and use that font?
Sep 30 '08 #2
vekipeki
229 Recognized Expert New Member
Well actually I haven't succeeded writing a superscript "+" sign using any of the common Windows fonts in w2k. For example, Arial Unicode MS font (which is said to be one of Microsoft's most-complete fonts in sense of unicode support), is not included by default in my win2k sp4 installation (does it come with Office?).

I don't like the idea of an application installing its fonts to the system, and I don't like the idea of using the Arial font instead of Tahoma just to get a couple of glyphs - I try to follow the Windows GUI design guidelines and they suggest avoiding non-system-default fonts in controls. I usually use SystemFonts.Mes sageBoxFont, and I presume (I hope correctly) that it will return a font which supports locale characters on a given machine - we might decide to localize our application to Chinese one day!

So at the end, what I wanted to avoid was using DrawString to manually create subscript and superscript signs because I thought the win2k and xp "unicode" fonts supported them.


I have two clean Virtual PC installations of win2k and xp, and have also modified my first program to try some other fonts:

Expand|Select|Wrap|Line Numbers
  1. using System.Windows.Forms;
  2. using System.Drawing;
  3.  
  4. public partial class Form1 : Form
  5. {
  6.     public Form1()
  7.     {
  8.         InitializeComponent();
  9.         this.Paint += new PaintEventHandler(Form1_Paint);
  10.     }
  11.  
  12.     void Form1_Paint(object sender, PaintEventArgs e)
  13.     {
  14.         string[] fontNames = new string[]
  15.              {  "Arial",
  16.                 "Tahoma",
  17.                 "Microsoft Sans Serif",
  18.                 "Arial Unicode MS",
  19.                 "Lucida Sans Unicode",
  20.                 "MS Sans Serif", 
  21.                 SystemFonts.DefaultFont.FontFamily.Name,
  22.                 SystemFonts.MessageBoxFont.FontFamily.Name };
  23.  
  24.         int yOffset = 10;
  25.  
  26.         foreach (string f in fontNames)
  27.             using (Font fnt = new Font(f, 12))
  28.             {
  29.                 e.Graphics.DrawString(fnt.FontFamily.ToString() + " \u2153", fnt, SystemBrushes.ControlText, new PointF(10, yOffset)); yOffset += 20;
  30.                 TextRenderer.DrawText(e.Graphics, fnt.FontFamily.ToString() + " \u2153", fnt, new Point(10, yOffset), SystemColors.ControlText); yOffset += 20;
  31.             }
  32.     }
  33. }
  34.  
It has a list of constant font family names, and two system defined fonts at the end. Windows XP shows the "1/3" glyph only with plain Arial font, but Win 2000 does not show it using any of the fonts.

Can anyone tell me if there is a font which works for you in w2k, and should be included by default?
Oct 1 '08 #3
Plater
7,872 Recognized Expert Expert
Have you checked using charmap?
I avoid win2k like the plague so I don't have access to it anymore.
Oct 1 '08 #4
vekipeki
229 Recognized Expert New Member
Thanks for the tip, I haven't used Char. map for a long time. I started it in both windows xp and 2000, and found which fonts support which glyphs.

They are pretty mixed up, so I will probably try to isolate those special glyphs and handle them separately, leaving MessageBoxFont as the default font for normal text. Should have done it in the first place! :)

Thanks!
Oct 1 '08 #5
mdjuit
1 New Member
How to use charmap for special character for writing a string in drawstring?

I have a long string, trying to print it using drawstring function, but the special character are getting doubled in the output print. Please help me how to use charmap to get rid of this problem. Your suggestion is very important for me
Feb 3 '10 #6
tlhintoq
3,525 Recognized Expert Specialist
ell actually I haven't succeeded writing a superscript "+" sign
It might just be easiest to check the unicode standard at unicode.org
http://www.unicode.org/charts/

You'll find that superscript plus is 207A
http://www.unicode.org/charts/PDF/U2070.pdf

1/3 is 2153
http://www.unicode.org/charts/PDF/U2150.pdf
Feb 4 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
2052
by: Jonah Olsson | last post by:
Hi guys! I'm trying to use Swedish characters with DrawString but no luck. Do I need to set the Charset somewhere?? I've been searching Google Groups for hours now, but I can't find any help or tutorial. Below is my code. Thanks for any kind of help! Regards, Jonah Olsson
5
27166
by: Charles A. Lackman | last post by:
Hello, I have created a complete PrintDocument and need to create an image from it. How is this done? e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality e.Graphics.DrawString(Line1.Text, FontLine1, TheBrush, Thelocation1, 390 + yPos, AStringFormat) e.Graphics.DrawString(Line2.Text, FontLine2, TheBrush, Thelocation2, TheHeight1 + (390 + yPos))
3
2253
by: Gürkan Demirci | last post by:
Hi, i am trying to write Jananese characters with DrawString(). It is not working. The characters a printed as boxes only. How can i change the culture of my windows forms application ? It seems not to work, because an additional textbox isn't printing in japanese charaters, too. best regards,
7
3037
by: Michael Galvin | last post by:
I am trying to use Python to send to the printer a calender filled with a mix of text and simple graphics. I want to draw on the printed page something like a table with 6 rows and 7 columns to represent a calendar. I want to place text precisely within those boxes on the printed page. I am using Python 2.4 on Windows XP I was in the past able to do this within Visual Basic using its printer object. Visual Basic's printer object uses...
7
2582
by: Peter Row | last post by:
Hi, I've started work on my own control some parts of which use standard controls, others I need to draw on my controls surface to get the display output I require, however.... I seem to be stupid or missing the point. I used DrawString( ) as a simple test but I cannot get it to work at all unless I handle my custom controls Paint event.
4
2988
by: grawsha2000 | last post by:
Hi, Is there a way to force Graphics.drawstring() method to display Hindi numbers when printing? I changed the locale settings of the Regional Options to an Arabic lang. but no luck. MTIA,
2
12659
by: Tony Johansson | last post by:
Hello! If I use the DrawString below with object of StringFormat as the last object it works good. If I instead remove object StringFormat below as the last object of DrawString I get some rows that are not printed correctly. It's look like when toner is too low for the printer.This is only for some rows. Can somebody explain why this happens? What kind of StringFormat is used when this parameter is missing?
6
2682
by: Dilip | last post by:
Howdy Folks I have a display where the Graphics.DrawString function is called to display something. Since the text seems to be larger than its bounding rectangle, the call basically splits the string into multiple lines. Is there a way to find out into how many lines the string was split? I am asking because this string is being displayed inside an owner
10
3649
by: anuking | last post by:
Hi, I made a tool that compares the texts from 2 richtextboxes and then marks the characters that are different in red. An option needs me to overlap these 2 text data to show the exact difference. I used a picturebox which is contained in a panel and draw the characters in respective colors using Graphics class. Everything is working fine, but for some reason I need to click the button twice to be able to see something on picturebox....
0
8983
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9528
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9359
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9310
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6792
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6072
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4592
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4863
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2774
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.