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.
Questions tagged [drawstring]
313 questions
1
vote
0 answers
Text drawn with GDI+ Graphics.DrawString jumps 1 pixel up when using StringTrimming.EllipsisCharacter
I'm using the classic DrawString method to output text in a WinForms app. A typical call look like this:
g.DrawString(text, font, brush, new Rectangle(x, y, width, height), stringFormat);
If stringFormat.Trimming equals…

TecMan
- 2,743
- 2
- 30
- 64
1
vote
1 answer
Win API Delphi GDI+: Drawing a String Inside a Child Window
When I draw a string using GDI+ in a child window, the text does not appear.
But when I change the child window to a normal window, the text appears normally. So here
is what I did so far:
program Test_Program;
Uses
Windows,
Messages,
…

Ismail Dz
- 67
- 1
- 10
1
vote
1 answer
Font is showing up too small or large when using .DrawString
I need to add a half inch of white space at the bottom of an image and the draw a string to the bottom left and bottom right (within the newly added white space). Everything seems to work fine but the font sometime appears way too small or too…

Garrett Lewis
- 11
- 2
1
vote
0 answers
Java drawString() very slow on start up
I'm new to Java programming and am having difficulty with the drawString method delaying almost a full second before drawing after the JFrame appears. Here is the test class I ran to verify it was drawString causing the delay(I'm sorry it is written…

Drew Walbeck
- 11
- 1
- 2
1
vote
1 answer
How to import a font from a .ttf file
I'm using Graphics.DrawString and I don't want to use Arial for my font but I don't know how to use/import one from file. This is my code.
using (Font myFont = new Font("Arial", 14))
{
Graphics.DrawString("Hello", myFont, Brushes.Black, new…

MahchinLizard
- 37
- 2
- 7
1
vote
2 answers
XNA 4.0: How to remove text after drawn to screen?
Good day everyone.
I'm trying to draw the text "Pass Complete!" to screen with this code:
spriteBatch.DrawString(font, "PASS COMPLETE!", new Vector2(30, 130), Color.White);
Which does fire off the proper IF statement. However, how do I go about then…

AriesTiger
- 69
- 1
- 8
1
vote
1 answer
How can i let g.drawstring handle \n?
Hi I am making a quiz application. I would like to draw the question on the screen. If the question is too long, I place a \n in the string so it should go to a newline. But g.drawstring doesn't recognize this \n.
This is my code :
/* Draw the…

user3485470
- 121
- 5
- 11
1
vote
1 answer
AWT Graphics DrawString results into incorrect width for Italic - Oblique Fonts
I have the below program to print a sentence string by string in java awt :
package awt;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import…

user3332322
- 9
- 4
1
vote
1 answer
Pack text into a JFrame?
I'm wondering if there is a way to make text wrap around when it reaches the end of a frame? When using the drawString method, if a line of text exceeds the length of the frame, it seems to just continue on and not wrap around. Does anyone know a…

Shaun
- 75
- 1
- 1
- 13
1
vote
3 answers
Graphics.DrawString doesn't work
I want to draw a text over a PictureBox in a foreach loop. This is the code that is responsible for rendering(GG is a PictureBox that is currently in the loop)
if (GG != null)
{
((PictureBox)GG).Image = (Image)obj;
…

vfioox
- 730
- 1
- 8
- 22
1
vote
0 answers
Graphics.setFont is slowing down my program
Graphics.setFont seems to cause a big delay in my paint() method:
g.setFont(gameOver);
g.drawString("GAME OVER!", getWidth()/2, getHeight() / 2);
gameOver is a font class variable(I read that it is more efficient to create a font prior to setting…

abaratham
- 445
- 1
- 5
- 19
1
vote
0 answers
Java AWT: Drawing Japanese text with Graphics2D.drawString()
I'm having issues drawing Japanese text with Graphics2D's drawString() method. The result is that a series of question marks ("????") is drawn instead of the specified Japanese text.
How can I draw Japanese text onto a BufferedImage with AWT?

Josh1billion
- 14,837
- 8
- 38
- 48
1
vote
0 answers
Slow drawing of strings in gdi+
I am creating a custom console in GDI+ and C# and I am drawing each character in the buffer individually (loops rows and columns). Now the default screen size for my console contains 1600 characters (80x20) and it ignores (doesn't draw) null…

Bryce Gough
- 11
- 1
1
vote
1 answer
Stretching the X or Y Axis on System.Graphics.DrawString
Is there a way to stretch the X or Y axis when calling System.Graphics.DrawString? We are working on laying out a graphics image (which is actually going to be printed) where it would be nice to make a particular piece of text say 125% higher than…

Jeff
- 8,020
- 34
- 99
- 157
1
vote
1 answer
Looped drawString not appearing in JFrame
I am trying to create a JFrame that displays a string in every even-numbered font size from 4 to 24. To do this I am trying to do a for loop that creates a drawString that uses a Font that increases in +2 font size everytime. Trying to get the next…

Novice
- 13
- 2