• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 352
  • Last Modified:

Strange drawstring problem with numbers

I have noticed that when I use drawstring to only print numbers, it just prints nothing. However if I put a letter in the string, it prints.

So, "12345" will not work, however
"a12345" will work.

Any help will be much appreciated!
Dim g As Graphics = e.Graphics
 
g.PageUnit = GraphicsUnit.Millimeter
 
g.DrawString("12345", myFont, getBrush(strColor), X, Y)

Open in new window

0
syinner
Asked:
syinner
  • 4
  • 3
1 Solution
 
Éric MoreauSenior .Net ConsultantCommented:
comment out this line and it will work:
'g.PageUnit = GraphicsUnit.Millimeter
0
 
syinnerAuthor Commented:
unfortunately that didn't work, and if it did, that would be crazy setting to remove!

how does changing the page unit allow me to print numbers?
0
 
Éric MoreauSenior .Net ConsultantCommented:
can you try this code as is:

    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        Dim myFont As Font = Me.Font
        Dim x As Integer = 10
        Dim y As Integer = 10
        Dim g As Graphics = e.Graphics

        g.PageUnit = GraphicsUnit.Display

        g.DrawString("12345", myFont, Brushes.Black, x, y)

    End Sub

If it is working like it is working for me, you may have a problem with your Font, your Brush, or your location.
0
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
syinnerAuthor Commented:
I tried changing to display but the same problem.

I don't believe its a problem with the location, brush etc because I add a letter into the string and it works with the same settings.

I still don't see how changing the display unit will stop numbers from being printed? when I can print letters, special characters and line breaks.

i have used the same unit to print lines and boxes.
0
 
Éric MoreauSenior .Net ConsultantCommented:
I can't help you more, it is working on my side.
0
 
syinnerAuthor Commented:
If I wanted to change the PageUnit permanently, it would be a big problem as its used allot.  

Anyone have any ideas why I am facing this strange problem with drawstring and numbers bearing in mind that it works fine for letters?
0
 
nailggCommented:
Hi syinner;

Dim g As Graphics = e.Graphics
Dim MyString as String
 
g.PageUnit = GraphicsUnit.Millimeter
MyString = "12345"
 
g.DrawString(MyString, myFont, getBrush(strColor), X, Y)

Open in new window

0
 
syinnerAuthor Commented:
Found the problem...I am using PaperlessPrinter to do my testing as this is in a vmware image... it was just not printing the line

Linked up my actual printer and it printed it!!!

Any suggestions on replacing this driver...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now