打印所选索引项

时间:2017-02-22 10:32:30

标签: vb.net printing

我尝试打印选定的索引项但我无法成功。

你能帮我修理一下代码吗?

我得到" -1"打印页面上的值。

Private Sub Textbox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged

    Dim idx As Integer = ListBox1.FindStringExact(TextBox2.Text)
                    If idx <> -1 Then
                        ListBox1.SelectedIndex = idx
                        ListBox2.Items.Add(ListBox1.Text)
                        ListBox1.Items.Remove(TextBox2.Text)
                        PrintDoc.Print()
    End sub

Private Sub PrintDoc_PrintPage(ByVal sender As System.Object, ByVal e As Printing.PrintPageEventArgs) Handles PrintDoc.PrintPage
        Dim drawfont As New Font("arial", 16)
        Dim drawbrush As New SolidBrush(Color.Black)
        e.Graphics.DrawString(ListBox1.SelectedIndex, drawfont, drawbrush, 100, 100)
    End Sub

1 个答案:

答案 0 :(得分:0)