Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6094159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:38:41+00:00 2026-05-23T12:38:41+00:00

I have the following code: public void DrawLetter(int Cell, string Letter, int X, int

  • 0

I have the following code:

public void DrawLetter(int Cell, string Letter, int X, int Y)
{
   System.Drawing.Font fBody = new System.Drawing.Font("Courier New", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));

   Pencil.DrawString(Letter, fBody, System.Drawing.Brushes.Black, X, Y);
   Pencil.DrawRectangle(new Pen(System.Drawing.Brushes.Red), X, Y, 10, 10);        
}

When I go through this twice and use 140,249 and 296,249 as co-ordinates the rectangle appears as I would expect in the correct position but the string appears a few pixels out and I can’t work out why.

I put in the DrawRectangle to check that it was starting in the correct position and it is. Am I doing something wrong in the DrawString? Also if I draw a D and a Z the width of the D is 10px and Z is 8px, I thought using Courier it would give me fixed width?

UPDATE: I looked at the sample on MSDN and here is a screenshot. Even though the DrawString is positioned at 0,0 you can see that the letter does not appear at 0,0. The rectangle does though. There must be padding or something:

Screenshot

UPDATE 2: Using the following code seems to improve things although its not perfect:

StringFormat strFormat = new StringFormat(StringFormat.GenericTypographic);
Pencil.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
Pencil.DrawString(measureString, stringFont, Brushes.Black, new PointF(0, 0), strFormat);

Screenshot 2

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:38:42+00:00Added an answer on May 23, 2026 at 12:38 pm

    It wouldn’t be the default padding / line-height etc being taken into account for the “Courier New” font would it?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

SO I have the following code public void rand(int N){ double[]x=new double[N]; double[]y=new double[N];
i have the following code public static void main(String[] args) { int x=0; int
I have following code public class TEST { public static void main(String arg[]){ try
I have the following code: public class ClassExample { void DoSomthing<T>(string name, T value)
I have the following code: public void post(String message) { final String mess =
I have the following code: public class Tests { public static void main(String[] args)
I have the following code: public void myMethod(Object... args) { System.out.println(this is myMethod); }
I have the following code: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.screen_database); db=new DBAdapter(this);
I have the following code: public void SetUser(User user) { string streetNumber = "";
I have the following code: public void DeleteAccountsForMonth(int year, int month) { var result

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.