如何使用带有动态和可打印图像的单元格创建网格。

Hui Liu-MSFT 40,866 信誉分 Microsoft 供应商
2024-04-11T06:58:26.97+00:00

下午好,就像我如何创建一个网格,每个单元格都有一个图像,该图像将是已经生成的二维码。按数字定义单元格数量并可打印 (vb.net)

Note:此问题总结整理于:how to create a grid with cells with images that is dynamic and printable.

VB
VB
Microsoft 开发的一种面向对象的编程语言,其在 .NET Framework 上实现。 以前称为 Visual Basic .NET。
59 个问题
0 个注释 无注释
{count} 票

接受的答案
  1. Jiale Xue - MSFT 34,501 信誉分 Microsoft 供应商
    2024-04-11T09:21:26.6466667+00:00

    离开预览控件(DataGridView或ListView),您可以直接打印图像。

        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load  
            ImageList1.ImageSize = New Size(PictureBox1.Width, PictureBox1.Height)  
        End Sub  
      
        Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click              
            ImageList1.Images.Add(PictureBox1.BackgroundImage)  
            Label1.Text = ImageList1.Images.Count  
        End Sub  
        Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage  
            Dim picCount As Integer = ImageList1.Images.Count  
            If picCount > 0 Then  
                Dim rect As Rectangle = e.MarginBounds  
                Dim width As Single = 1.0F * rect.Width / 3  
                Dim height As Single = width  
                Dim columns = 3  
                Dim ypos = 0  
                Dim index As Integer = 0  
                While ypos + height < 1.0F * rect.Height  
                    For c As Integer = 0 To columns - 1  
      
                        Dim pRect As RectangleF = New RectangleF(c * width, ypos, width, height)  
                        e.Graphics.DrawImage(ImageList1.Images(index), pRect)  
                        index += 1  
                        If index > ImageList1.Images.Count - 1 Then  
                            Return  
                        End If  
                    Next  
                    ypos = ypos + height  
                End While  
                e.HasMorePages = True  
            Else  
                MessageBox.Show("You must generate qr code first")  
            End If  
        End Sub  
            
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click  
            Dim qrGenerator As QRCodeGenerator = New QRCodeGenerator()  
            Dim qrCodeData As QRCodeData = qrGenerator.CreateQrCode("Hello world", QRCodeGenerator.ECCLevel.Q)  
            Dim qrCode As QRCode = New QRCode(qrCodeData)  
            Dim qrCodeImage As Bitmap = qrCode.GetGraphic(20)  
            PictureBox1.BackgroundImage = qrCodeImage  
        End Sub  
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click  
      
            Dim printDialog As PrintDialog = New PrintDialog()  
            printDialog.Document = PrintDocument1  
            If printDialog.ShowDialog() = DialogResult.OK Then  
                PrintDocument1.Print()  
            End If  
        End Sub  
    

    测试结果。

    96682-1.png


    如果答案是正确的,请点击“接受答案”并点赞。 如果您对此答案还有其他疑问,请点击“评论”。

    注意:如果您想接收相关电子邮件,请按照我们的文档中的步骤启用电子邮件通知 此线程的通知。

    0 个注释 无注释

0 个其他答案

排序依据: 非常有帮助