Results 1 to 6 of 6

Thread: PrintDialog PrintDocument Change the font

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2016
    Posts
    16

    PrintDialog PrintDocument Change the font

    Hi All

    I have created a form that collects data for bar codes the data is then Encode and the bar code is displayed in a text box.

    However when I try and print the text box only I just get nonsense printed.

    I am using IDAutomationSC128S Demo Symbol font to generate the barcode, do i need to change the PrintDocument font (if i can)?


    Thanks in advance




    Private Sub txtBarcode_TextChanged(sender As Object, e As EventArgs) Handles txtBarcode.TextChanged

    End Sub

    Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click

    PrintDialog3.AllowSomePages = True
    PrintDialog3.ShowHelp = True
    If PrintDialog3.ShowDialog = DialogResult.OK Then
    If txtBarcode.Text <> "" Then
    PrintDocument3.Print()

    End If
    End If
    End Sub

    Private Sub PrintDocument3_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument3.PrintPage
    e.Graphics.DrawString(txtBarcode.Text, Me.Font, Brushes.Black, e.MarginBounds, StringFormat.GenericTypographic)

    End Sub
    End Class

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,020

    Re: PrintDialog PrintDocument Change the font

    There is no PrintDocument font. The PrintPage event handler is where you specify what to print and, if you specify text, that's where you specify the font. What did you think this was:
    Code:
    e.Graphics.DrawString(txtBarcode.Text, Me.Font, Brushes.Black, e.MarginBounds, StringFormat.GenericTypographic)
    If you are displaying the barcode in a TextBox using the correct font then you probably need the Font of that TextBox, i.e. txtBarcode.Font, rather than the Font of the form.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2016
    Posts
    16

    Re: PrintDialog PrintDocument Change the font

    Hi thanks for the response, this is the font i am using for the barcode "IDAutomationSC128S Demo Symbol"

    Sorry i dont understand where the to enter the font name, do i change the me.font to the font name IDAutomationSC128S Demo Symbol?

    Many Thanks


    Private Sub btnCreate_Click(sender As Object, e As EventArgs) Handles btnCreate.Click
    txtEncodedText.Text = FontEncoder.Code128(txtDataToEncode.Text)

    txtBarcode.Text = txtEncodedText.Text

    txtBarcode.Font = New System.Drawing.Font("IDAutomationSC128S Demo Symbol", 20, FontStyle.Regular)

  4. #4
    Frenzied Member
    Join Date
    Nov 2017
    Posts
    1,057

    Re: PrintDialog PrintDocument Change the font

    Sorry i dont understand where the to enter the font name
    Not sure how else jmc could have made it more clear. He quoted the pertinent line of code, and underlined and made red the parameter that handles what font gets printed.

    Me.Font is the Font used by the form. Do you want the entire Form to use the barcode font? I would imagine not.

    So, don't pass Me.Font. Pass the font you want. You could do this in multiple ways, but the most simple way would probably be to replace Me.Font with txtBarcode.Font in the line of code jmc quoted. Which is exactly what jmc suggested.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Sep 2016
    Posts
    16

    Re: PrintDialog PrintDocument Change the font

    Thats fixed it, just need pointing in the right direction, thanks to both of you, I am still learning this and believe me I did look at you tube google before I came on here for advice you have made my day

  6. #6
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,020

    Re: PrintDialog PrintDocument Change the font

    Quote Originally Posted by coyney22 View Post
    I did look at you tube google before I came on here
    I just searched for "vb.net printdocument font" and the first result was the official documentation for the PrintDocument class that provides an example of printing text with a specific font.

    https://docs.microsoft.com/en-us/dot...ramework-4.7.2

    The second result was another example showing how to print with a specific font.

    https://bytes.com/topic/visual-basic...nt-font-dialog

    It seems to me that a lot of beginners are genuinely terrible at searching the web. I'm not sure why that is but I think it might be that they don't actually recognise what a KEY WORD search is. As you can see, I searched using only a few RELEVANT key words, i.e. the words that are key to the subject I'm searching on. I think that many beginners search using long, natural language sentences that will inherently filter out results that lack the irrelevant words they have included. The key to good searching is understanding the key to what you're searching for. You should almost always start with fewer key words and add later rather than start with loads and remove.

    Quote Originally Posted by coyney22 View Post
    just need pointing in the right direction
    I kinda thought that that's what I did in post #2, but all's well that ends well. Just like working out what's key when deciding what to search for, you need to get better at working out what's key in the information you read, which you will in time.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width