我正在尝试在编号的程序中打印组合框的所有内容。
ComboBox1内容:
Yes
No
Maybe
No Opinion
到目前为止,我的代码是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
例如,所需的输出为:
1. Yes
2. No
3. Maybe
4. No Opinion
谢谢!
答案 0 :(得分:1)
您需要遍历ComboBox
Items集合以获取您的值,如下所示。
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