Welcome to Dream.In.Code
Become a C# Expert!

Join 150,407 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 947 people online right now. Registration is fast and FREE... Join Now!




Question regarding drawing string

 
Reply to this topicStart new topic

Question regarding drawing string

cygnusX
18 Mar, 2008 - 11:27 AM
Post #1

D.I.C Head
**

Joined: 19 May, 2007
Posts: 159



Thanked: 2 times
My Contributions
I'm drawing string at the KeyUp event of a custom control.How to draw special character like empty space or * or # or @ or whatever...I mean when i try to draw for example empty space character the DrawString draws "space" instead of ' '.Obviously i don't want this.How to solve this problem?
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Question Regarding Drawing String
18 Mar, 2008 - 11:51 AM
Post #2

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,483



Thanked: 161 times
Dream Kudos: 9075
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
You're going to want to use something like


csharp

//create our image
Image test = (Image) new Bitmap(200, 200);

//create our graphic object
Graphics graphic = Graphics.FromImage(test);

//set up our special character (U+00AE = ®)
string character = "\00AE";

//create our font
Font font = new Font(fontFamily,20,style,GraphicsUnit.Pixel);

//create string format
StringFormat sf = new StringFormat();
sf.FormatFlags = StringFormatFlags.FitBlackBox |
StringFormatFlags.NoClip | StringFormatFlags.NoWrap;
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;

// Draw string to image.
gs.DrawString(character, font, Brushes.Black, new PointF(100,100), sf);


That will draw the special character ®
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Question Regarding Drawing String
18 Mar, 2008 - 11:58 AM
Post #3

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,660



Thanked: 314 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
What font are you using? Can you also show us the keyup event that you are using to do the drawstring? And any paint event that you may have in place that could also be doing the drawstring. Thanks!
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 07:29PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month