0

I am trying to print all the contents of a combobox in a program, numbered.

ComboBox1 contents:

Yes

No

Maybe

No Opinion

My code so far for PrintDocument1:

Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
    Dim horizontalPrintPosition As Single
    Dim verticalPrintPosition As Single
    Dim PrintFont As New Font("Arial", 12)
    e.Graphics.DrawString("Info from ComboBox1 would go here", PrintFont, Brushes.Black, horizontalPrintPosition, verticalPrintPosition)
End Sub

For example, the desired output would be:

1. Yes

2. No

3. Maybe

4. No Opinion

Thanks!

NeverHopeless
  • 11,077
  • 4
  • 35
  • 56
wathsun
  • 11
  • 1
  • 1
  • 1
    The code you post doesn't seems to be related to your problem. What have you tried to print the numbered version? http://whathaveyoutried.com/ – ForceMagic Nov 11 '12 at 01:47

1 Answers1

1

You will need to iterate through the ComboBox Items collection to get your values, something like this.

Private Sub PrintDocument1_PrintPage(sender As System.Object, e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
    Dim horizontalPrintPosition As Single
    Dim verticalPrintPosition As Single
    Dim PrintFont As New Font("Arial", 12)

    For x = 0 To ComboBox1.Items.Count - 1
        e.Graphics.DrawString((x + 1).ToString() & ". " & ComboBox1.Items(x).ToString(), PrintFont, Brushes.Black, horizontalPrintPosition, verticalPrintPosition)
        verticalPrintPosition += PrintFont.Height
    Next

End Sub
Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
Mark Hall
  • 53,938
  • 9
  • 94
  • 111