Udskrivning af flere stregkoder i Windows-formularapplikation. NET C #

Indlæg af Hanne Mølgaard Plasc

Problem



Indtast billedbeskrivelse her [2]


nedenfor er min kode


Tegn metode er nedenfor:
Nu når jeg genererer koden erstatter den den eksisterende stregkode og placerer ikke en ny stregkode i billedkassen.


System.Drawing.Graphics g = this.pictureBox1.CreateGraphics();
g.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.SystemColors.Control), new Rectangle(x, y, 50, 50));
ean13.Scale = 1.0F;
ean13.DrawEan13Barcode(g, new System.Drawing.Point(a, a));
public void DrawEan13Barcode( System.Drawing.Graphics g, System.Drawing.Point pt )
{
    float width = this.Width * this.Scale;
    float height = this.Height * this.Scale;

    //  EAN13 Barcode should be a total of 113 modules wide.
    float lineWidth = width / 113f;

    // Save the GraphicsState.
    System.Drawing.Drawing2D.GraphicsState gs = g.Save( );

    // Set the PageUnit to Inch because all of our measurements are in inches.
    g.PageUnit = System.Drawing.GraphicsUnit.Millimeter;

    // Set the PageScale to 1, so a millimeter will represent a true millimeter.
    g.PageScale = 1;

    System.Drawing.SolidBrush brush = new System.Drawing.SolidBrush( System.Drawing.Color.Black );

    float xPosition = 0;

    System.Text.StringBuilder strbEAN13 = new System.Text.StringBuilder( );
    System.Text.StringBuilder sbTemp = new System.Text.StringBuilder( );

    float xStart = pt.X;
    float yStart = pt.Y;
    float xEnd = 0;

    System.Drawing.Font font = new System.Drawing.Font( "Arial", this.\_fFontSize * this.Scale );

    // Calculate the Check Digit.
    this.CalculateChecksumDigit( );

    sbTemp.AppendFormat( "{0}{1}{2}{3}", 
        this.CountryCode,
        this.ManufacturerCode,
        this.ProductCode, 
        this.ChecksumDigit );


    string sTemp = sbTemp.ToString( );

    string sLeftPattern = "";

    // Convert the left hand numbers.
    sLeftPattern = ConvertLeftPattern( sTemp.Substring( 0, 7 ) );

    // Build the UPC Code.
    strbEAN13.AppendFormat( "{0}{1}{2}{3}{4}{1}{0}",
        this.\_sQuiteZone, this.\_sLeadTail,
        sLeftPattern,                   
        this.\_sSeparator,
        ConvertToDigitPatterns( sTemp.Substring( 7 ), this.\_aRight ) );

    string sTempUPC = strbEAN13.ToString( );

    float fTextHeight = g.MeasureString( sTempUPC, font ).Height;

    // Draw the barcode lines.
    for( int i = 0; i < strbEAN13.Length; i++ )
    {
        if( sTempUPC.Substring( i, 1 ) == "1" )
        {
            if( xStart == pt.X )
                xStart = xPosition;

            // Save room for the UPC number below the bar code.
            if( ( i > 12 && i < 55 ) || ( i > 57 && i < 101 ) )
                // Draw space for the number
                g.FillRectangle( brush, xPosition, yStart, lineWidth, height - fTextHeight );
            else
                // Draw a full line.
                g.FillRectangle( brush, xPosition, yStart, lineWidth, height );
        }

        xPosition += lineWidth;
        xEnd = xPosition;
    }

    // Draw the upc numbers below the line.
    xPosition = xStart - g.MeasureString( this.CountryCode.Substring( 0, 1 ), font ).Width;
    float yPosition = yStart + ( height - fTextHeight );

    // Draw 1st digit of the country code.
    g.DrawString( sTemp.Substring( 0, 1 ), font, brush, new System.Drawing.PointF( xPosition, yPosition ) );

    xPosition += ( g.MeasureString( sTemp.Substring( 0, 1 ), font ).Width + 43 * lineWidth ) -
        ( g.MeasureString( sTemp.Substring( 1, 6 ), font ).Width );

    // Draw MFG Number.
    g.DrawString( sTemp.Substring( 1, 6 ), font, brush, new System.Drawing.PointF( xPosition, yPosition ) );

    xPosition += g.MeasureString( sTemp.Substring( 1, 6 ), font ).Width + ( 11 * lineWidth );

    // Draw Product ID.
    g.DrawString( sTemp.Substring( 7 ), font, brush, new System.Drawing.PointF( xPosition, yPosition ) );

    // Restore the GraphicsState.
    g.Restore( gs );
}


public System.Drawing.Bitmap CreateBitmap( )
{
    float tempWidth = ( this.Width * this.Scale ) * 100 ;
    float tempHeight = ( this.Height * this.Scale ) * 100;

    System.Drawing.Bitmap bmp = new System.Drawing.Bitmap( (int)tempWidth, (int)tempHeight );

    System.Drawing.Graphics g = System.Drawing.Graphics.FromImage( bmp );
    this.DrawEan13Barcode( g, new System.Drawing.Point( 0, 0 ) );
    g.Dispose( );
    return bmp;
}


hvis der er en alternativ måde at gøre dette på, er kravet klart


tegne og udskrive N antal stregkoder ved hjælp af Windows-formularer

Bedste reference


du kan generere stregkode og gemme sit billede i database sql server.
derefter opret krystal rapport og få det felt på krystal rapport detaljer sektion. du får hvad du har brug for.