BC30311 “矩形”类型的值无法转换为“矩形”错误 VB.net

BC30311 Value of type 'Rectangle' cannot be converted to 'Rectangle' error in VB.net

提问人:Waqar Vickey 提问时间:11/15/2022 更新时间:11/15/2022 访问量:90

问:

我已经看过很多教程来获取打印dataGridView并下载一个运行良好的项目,但是当我尝试将其放入自己的项目中时,我遇到了错误 BC30311 “Rectangle”类型的值不能转换为“Rectangle”

Private bitmap As Bitmap
    Private Sub BtnPrintCS_Click(sender As Object, e As EventArgs) Handles BtnPrintCS.Click
        'Resize DataGridView to full height.
        Dim height As Integer = DataLockersList.Height
        DataLockersList.Height = DataLockersList.RowCount * DataLockersList.RowTemplate.Height
        'Dim widDoc As Integer = Me.DataLockersList.Width
        'Dim higDoc As Integer = Me.DataLockersList.Height
        'Dim rectangle1 As New Rectangle(0, 0, widDoc, higDoc)
        'Create a Bitmap and draw the DataGridView on it.
        bitmap = New Bitmap(Me.DataLockersList.Width, Me.DataLockersList.Height)

        DataLockersList.DrawToBitmap(bitmap, New Rectangle(0, 0, Me.DataLockersList.Width, Me.DataLockersList.Height))

        'Resize DataGridView back to original height.
        DataLockersList.Height = height

        'Show the Print Preview Dialog.
        PrintPreviewDialog1.Document = PrintDocument1
        PrintPreviewDialog1.PrintPreviewControl.Zoom = 1
        PrintPreviewDialog1.ShowDialog()
    End Sub

    Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        'Print the contents.
        e.Graphics.DrawImage(bitmap, 0, 0)
    End Sub
vb.net visual-studio-2010 打印

评论

0赞 Andrew Mortimer 11/15/2022
将“Option Explicit”和“Option Strict”切换为“打开”,并检查要创建的 Rectangle 是否来自 DrawToBitmap 方法的预期命名空间。
0赞 Waqar Vickey 11/15/2022
@AndrewMortimer 如何检查您创建的 Rectangle 是否来自 DrawToBitmap 方法的预期命名空间。

答: 暂无答案