0

I have a little problem. Graphics.DrawString method is not drawing text from upper left corner but fewer pixels under and few pixels more on right side then it schould. There is my code:

graphics.DrawString("TeSt", new Font("Arial", sizeOfFont), blackOne.Brush, 0, 0);

and there is a result:

enter image description here

How can u see text is shifted few pixels down and right when rectangle behind "TeSt" is drawn correctly from (0, 0) point. I tried everything and there is my question. Did i missed somethink or just it is like it is, if so then why?

SEGMK
  • 130
  • 1
  • 8
  • Do you have any active _[transforms?](https://learn.microsoft.com/en-us/dotnet/desktop/winforms/advanced/using-the-world-transformation?view=netframeworkdesktop-4.8)_. Try performing a `graphics.Transform = new Matrix()` –  Aug 02 '21 at 00:34
  • 1
    That's the default padding. It's fully applied when you specify a Point instead of a Rectangle and no StringFormat options to position the Text. Defining the text position as *fewer pixels under and few pixels more on right side than it should* is not correct: the text is drawn exactly how you asked. -- If you're drawing on a Bitmap, I suggest this method: [Remove top and bottom padding from Text drawn on an Image](https://stackoverflow.com/a/54383828/7444103). Otherwise, you need to describe the actual *canvas*. – Jimi Aug 02 '21 at 01:40
  • If you're drawing on a Control's surface (or Items of a list presenter, as ListBox, ListView etc.), prefer `TextRenderer.DrawText()` to `Graphics.DrawString()`. Specify the `TextFormatFlags` needed to draw the text as you want it to be. – Jimi Aug 02 '21 at 01:57

0 Answers0