Questions tagged [drawstring]

Graphics.DrawString is a method in the .Net Framework's System.Drawing namespace, by which code can draw text onto an image in .Net code. This is mainly used in ASP.Net, as TextRenderer.DrawText (from System.Windows.Forms) provides more reliable functionality in Windows Forms applications.

313 questions
7
votes
1 answer

Graphics.DrawString() vs TextRenderer.DrawText()

I am confused about these two methods. My understanding is that Graphics.DrawString() uses GDI+ and is a graphics-based implementation, while TextRenderer.DrawString() uses GDI and allows a large range of fonts and supports unicode. My issue is when…
MarkChimes
  • 109
  • 1
  • 6
7
votes
2 answers

How to draw a rotated string as an image with System.Drawing?

I am drawing strings to images. The size of the images is dynamic, or in other words, the images are as large as necessary to display the strings. To achieve that I am measuring the size with Graphics.MeasureString() before rendering the text with…
asp_net
  • 3,567
  • 3
  • 31
  • 58
7
votes
2 answers

Determining bitmap size to hold text string

What I am trying to do is use the DrawString() method to draw a string to a bitmap. To do this, I need to create a bitmap and get a Graphics object from the bitmap, then call DrawString() on that Graphics object. The problem is, how do I know, in…
Icemanind
  • 47,519
  • 50
  • 171
  • 296
6
votes
5 answers

How can drawString method be used for writing diagonal way

I am using c# 2005 i want to write string diagonally on image. But by default c# provides the option to write horizontally or vertically. how we write diagonally? Thanks
SelvirK
  • 925
  • 3
  • 18
  • 42
6
votes
3 answers

Centering an individual character with DrawString

I have tried all of the suggested ways to center text, but I can't seem to get the results I want while centering an individual character. I have a rectangle. In that rectangle I'm drawing a circle with DrawEllipse. Now I want to draw a single…
Trevor Elliott
  • 11,292
  • 11
  • 63
  • 102
6
votes
3 answers

Why is DrawString exhibiting unexpected behavior in C# Winforms?

I have subclassed a control in C# WinForms, and am custom drawing text in my OnPaint() handler. The font is set to Courier New using the following code in my form: FontFamily family = new FontFamily("Courier New"); this.myControl.Font = new…
Ko9
  • 199
  • 1
  • 3
  • 9
6
votes
1 answer

C# Graphics.DrawString RectangleF Auto-Height: How to find that height?

I am writing text over an image using Graphics DrawString method, binding my text with a RectangleF. Here is my code: //Write header2 RectangleF header2Rect = new RectangleF(); header2Rect.Width = 600; header2Rect.Location = new Point(30,…
Evan Layman
  • 3,691
  • 9
  • 31
  • 48
6
votes
3 answers

Draw Rotated Text around it's center with RotateTransform

I have this code in C# to draw the rotated text Font font = new Font("Arial", 80, FontStyle.Bold); int nWidth = pictureBox1.Image.Width; int nHeight = pictureBox1.Image.Height; Graphics g =…
Mario
  • 13,941
  • 20
  • 54
  • 110
6
votes
2 answers

Windows DPI setting affects Graphics.DrawString

I have created a new Bitmap object and now want do draw some text to it using GDI+. So I call Graphics.DrawString(...). The problem is that the size of the string depends on Windows 7's DPI settings. Is there any way to make my text drawing…
Boris
  • 8,551
  • 25
  • 67
  • 120
5
votes
2 answers

Break lines in g.drawString in Java SE

This is exactly what I'm trying to do: Graphics2D g2 = (Graphics2D) g; g2.setFont(new Font("Serif", Font.PLAIN, 5)); g2.setPaint(Color.black); g2.drawString("Line 1\nLine 2", x, y); That line prints like this: Line1Line2 I want it like…
ArMEd
  • 121
  • 1
  • 4
  • 11
5
votes
0 answers

TextRenderer.DrawText using GDI to render OTF Fonts?

I'm trying to draw text over a bitmap image and I've done some research and found that .NET/GDI+ doesn't support OTF fonts. I read somewhere that you could use TextRenderer.DrawText to render OTF fonts with GDI, but I can't seem to figure out how,…
Evan Layman
  • 3,691
  • 9
  • 31
  • 48
5
votes
6 answers

Determining the number of lines in a text string?

As part of a printing class, I want to be able to print long strings over multiple pages, but I don't know how to calculate the height of the entire string, which I will determine by first counting the number of lines in my string. I know I can…
sooprise
  • 22,657
  • 67
  • 188
  • 276
5
votes
1 answer

How to position a python Reportlab table at position 10,100 and use drawString

I am a python hobbyist and reportlab newbie. I know how to use drawString to put text at a particular place on a page, e.g.: c.drawString(10,100,"Welcome to Reportlab!") But I can't figure out how to place a table (which will only be a few lines…
Marc B. Hankin
  • 771
  • 3
  • 15
  • 31
5
votes
2 answers

Graphics.DrawString highlight specific words

I am using Graphics.DrawString in an ObjectListView. I need to highlight some words in the string (make their background yellow). Can this be done? Before using Graphics.DrawString, I could use DefaultRenderer for highlighting. But now it doesn't…
Jerry
  • 4,258
  • 3
  • 31
  • 58
5
votes
1 answer

Graphics DrawString with controlled Word Wrap

Basically my issue is that I need to word wrap a string when I want to. Not when .NET wants to. I understand that the DrawString method will automatically word wrap if I give it a rectangle to draw within. I need to control when it does word wrap…
Travyguy9
  • 4,774
  • 8
  • 43
  • 63
1
2
3
20 21