Reference Guide
Programming / Barcode Reading & Writing / Drawing 1D barcode via mouse on your document
In This Topic
    Drawing 1D barcode via mouse on your document
    In This Topic

    You can draw 1D barcodes using GdPicture. For ease of use, here is a small code example, that will draw the barcode in the area of a rectangle you select on the image.

    Copy Code
    ''' <summary>
    ''' On the Mouse UP event on the GdViewer, draw a 1D barcode.
    ''' </summary>
    ''' <param name=" eventSender ">The object which the event has occurred on.
    ''' <param name=" eventArgs ">The events data.
    ''' <remarks>
    ''' If no rectangle of selection was painted on the GdViewer, this event will do nothing.
    ''' </remarks>
    Public Sub Draw_Barcode(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles GdViewer1.MouseUp
       'Initializing variables to hold the position of the rectangle of selection on the document.
       Dim leftArea As Integer, topArea As Integer, widthArea As Integer, heightArea As Integer
       'Checking if a rectangle of selection has been painted on the GdViewer.
       If GdViewer1.IsRect() Then
          'Getting the location of the selection on the document.
          GdViewer1.GetRectCoordinatesOnDocument(leftArea, topArea, widthArea, heightArea) 
    
          Dim barcodeType As Barcode1DWriterType = Barcode1DWriterType.Barcode1DWriterCode128
          'Drawing the 1D barcode.
          Dim status As GdPictureStatus = oGdPictureImaging.Barcode1DWrite(imageId, barcodeType, "GdPicture 1D Barcode", leftArea, topArea, widthArea, heightArea, oGdPictureImaging.ARGB(255, 0, 0, 0))
          If status <> GdPictureStatus.OK Then
             MessageBox.Show("ERROR: " + status.ToString(), "Barcode Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
          Else
             'Redrawing the whole image.
             GdViewer1.Redraw()
          End If
       End If
    End Sub
    Copy Code
    /// <summary>
    /// On the Mouse UP event on the GdViewer, draw a 1D barcode.
    /// </summary>
    /// <param name=" eventSender ">The object which the event has occurred on.
    /// <param name=" eventArgs ">The events data.
    /// <remarks>
    /// If no rectangle of selection was painted on the GdViewer, this event will do nothing.
    /// </remarks>
    public void Draw_Barcode(System.Object eventSender, System.EventArgs eventArgs)
    {
        //Initializing variables to hold the position of the rectangle of selection on the document.
        int leftArea = 0;
        int topArea = 0;
        int widthArea = 0;
        int heightArea = 0;
        //Checking if a rectangle of selection has been painted on the GdViewer.
        if (GdViewer1.IsRect())
        {
            //Getting the location of the selection on the document.
            GdViewer1.GetRectCoordinatesOnDocument(ref leftArea, ref topArea, ref widthArea, ref heightArea); 
    
            Barcode1DWriterType barcodeType = Barcode1DWriterType.Barcode1DWriterCode128;
            //Drawing the 1D barcode.
            GdPictureStatus status = oGdPictureImaging.Barcode1DWrite(imageId, barcodeType, "GdPicture 1D Barcode", leftArea, topArea, widthArea, heightArea, oGdPictureImaging.ARGB(255, 0, 0, 0));
            if (status != GdPictureStatus.OK)
            {
                MessageBox.Show("ERROR: " + status.ToString(), "Barcode Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                //Redrawign the whole image.
                GdViewer1.Redraw();
            }
        }
    }