Reputation: 369
I trying to add and resize with rectangle from one Picture box barcode and Another picture box QR to label in run time with VB.NET
is there any other method or solution I can do add and resize with rectangle like the gif file below ?
Please Guide me
Thanks
Imports System.ComponentModel
Imports ZXing
Imports ZXing.Common
<Assembly: CLSCompliant(True)>
Partial Public Class LabelWYSIWYG
Inherits UserControl
Public Sub New()
' This call is required by the designer.
InitializeComponent()
'' Add any initialization after the InitializeComponent() call.
'Label1.Size = 80,50
Me.Label1.Size = New System.Drawing.Size(100, 60)
' Populate the dropdown with supported barcode formats
ComboBox1D.Items.Add("EAN_13")
ComboBox1D.Items.Add("CODABAR")
ComboBox1D.Items.Add("CODE_39")
ComboBox1D.Items.Add("CODE_93")
ComboBox1D.Items.Add("CODE_128")
ComboBox1D.Items.Add("EAN_8")
ComboBox1D.Items.Add("ITF")
ComboBox1D.Items.Add("UPC_A")
ComboBox1D.Items.Add("UPC_E")
ComboBox1D.SelectedIndex = -1
ComboBox2D.Items.Add("AZTEC")
ComboBox2D.Items.Add("DATA_MATRIX")
ComboBox2D.Items.Add("PDF_417")
ComboBox2D.Items.Add("QR_CODE")
ComboBox2D.SelectedIndex = -1
End Sub
Private Sub GenerateBarcode1D()
Dim writer As New BarcodeWriter()
Dim format As BarcodeFormat
Select Case Me.ComboBox1D.Text
Case "CODABAR"
format = BarcodeFormat.CODABAR
Case "CODE_39"
format = BarcodeFormat.CODE_39
Case "CODE_93"
format = BarcodeFormat.CODE_93
Case "CODE_128"
format = BarcodeFormat.CODE_128
Case "EAN_8"
format = BarcodeFormat.EAN_8
Case "EAN_13"
format = BarcodeFormat.EAN_13
Case "ITF"
format = BarcodeFormat.ITF
Case "UPC_A"
format = BarcodeFormat.UPC_A
Case "UPC_E"
format = BarcodeFormat.UPC_E
End Select
writer.Format = format
Dim options As New EncodingOptions()
options.Height = txtBH.Value
options.Width = txtBW.Value
options.Margin = 10
writer.Options = options
Dim barcodeBitmap As Bitmap = writer.Write(txtBarcode.Text)
Dim finalBitmap As New Bitmap(CInt(txtBH.Value), CInt(txtBW.Value))
Dim graphics As Graphics = Graphics.FromImage(finalBitmap)
Try
' Clear the background with white color
graphics.Clear(Color.White)
' Draw the barcode onto the final bitmap
Dim barcodeX As Integer = (txtBW.Value)
Dim barcodeY As Integer = (txtBH.Value)
graphics.DrawImage(barcodeBitmap, barcodeX, barcodeY)
Finally
' Dispose graphics object to free resources
graphics.Dispose()
End Try
PictureBoxBarcode.Image = finalBitmap
End Sub
Private Sub GenerateBarcode2D()
Dim writer As New BarcodeWriter()
Dim format As BarcodeFormat
Select Case Me.ComboBox2D.Text
Case "AZTEC"
format = BarcodeFormat.AZTEC
Case "DATA_MATRIX"
format = BarcodeFormat.DATA_MATRIX
Case "PDF_417"
format = BarcodeFormat.PDF_417
Case "QR_CODE"
format = BarcodeFormat.QR_CODE
End Select
writer.Format = format
Dim options As New EncodingOptions()
options.Height = txtBH.Value
options.Width = txtBW.Value
options.Margin = 10
writer.Options = options
Dim barcodeBitmap As Bitmap = writer.Write(txtBarcode.Text)
Dim finalBitmap As New Bitmap(CInt(txtBH.Value), CInt(txtBW.Value))
Dim graphics As Graphics = Graphics.FromImage(finalBitmap)
Try
' Clear the background with white color
graphics.Clear(Color.White)
' Draw the barcode onto the final bitmap
Dim barcodeX As Integer = (txtBW.Value)
Dim barcodeY As Integer = (txtBH.Value)
graphics.DrawImage(barcodeBitmap, barcodeX, barcodeY)
Finally
' Dispose graphics object to free resources
graphics.Dispose()
End Try
PictureBoxQr.Image = finalBitmap
End Sub
End Class
#Region "EventArgs extension and event delegates"
''' <summary>
''' Class to extend EventArgs with a cancel parameter.
''' </summary>
Public Class LabelWYSIWYGEventArgs
Inherits EventArgs
''' <summary>
''' Gets or sets a value indicating whether this <see cref="LabelWYSIWYGEventArgs"/> is cancel.
''' </summary>
''' <value><c>true</c> if cancel; otherwise, <c>false</c>.</value>
Private _cancel As Boolean
Public Property Cancel As Boolean
Get
Return Me._cancel
End Get
Set(ByVal value As Boolean)
Me._cancel = value
End Set
End Property
End Class
Public Delegate Sub LabelWYSIWYGOnOpen(ByVal sender As Object, ByVal e As LabelWYSIWYGEventArgs)
Public Delegate Sub LabelWYSIWYGOnSave(ByVal sender As Object, ByVal e As LabelWYSIWYGEventArgs)
#End Region ' EventArgs extension and event delegates
result interface in usercontrol
Desired result like below file gif
Upvotes: 0
Views: 47