Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Apr 2012
    Posts
    24
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Arrow Adding external class to my Form1.cs HELP

    Hi codingforums, I am in need of help adding this class(ean13.cs): http://www.codeproject.com/Articles/...arcodes-with-C

    to my Form1.cs class. Its an external class called EAN13.cs and I need it inside of my Form1.cs but I do not know how to do this
    It is just a regular form1.cs class that you initially create when you launch a 'New Project' in VS.

    Please help
    Last edited by nickslick; 04-18-2012 at 04:56 PM.

  • #2
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,718
    Thanks
    41
    Thanked 191 Times in 190 Posts
    I really do not understand what you need help w/ in "adding the class" ...
    classes are just referenced by namespace...
    Code:
    namespace dog
    class puppy
    class doggy
    then to reference it
    Code:
    using dog;
    
    namespace animals
    class quadrapeds(){
    dog _d = new dog();
    .... etc

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • #3
    New Coder
    Join Date
    Apr 2012
    Posts
    24
    Thanks
    4
    Thanked 0 Times in 0 Posts
    hey alykins, sorry about the confusion but I meant, adding the Ean13.cs' contents to my Form1.cs. similar to this:
    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace WindowsFormsApplication2
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    class Ean13
      {
          private string _sName = "EAN13";
    
          private float _fMinimumAllowableScale = .8f;
          private float _fMaximumAllowableScale = 2.0f;
    
          // This is the nomimal size recommended by the EAN.
          private float _fWidth = 37.29f;
          private float _fHeight = 25.93f;
          private float _fFontSize = 8.0f;
          private float _fScale = 1.0f;
    
          // Left Hand Digits.
          private string [] _aOddLeft = { "0001101", "0011001", "0010011", "0111101", 
                                            "0100011", "0110001", "0101111", "0111011", 
                                            "0110111", "0001011" };
    
          private string [] _aEvenLeft = { "0100111", "0110011", "0011011", "0100001", 
                                             "0011101", "0111001", "0000101", "0010001", 
                                             "0001001", "0010111" };
    
          // Right Hand Digits.
          private string [] _aRight = { "1110010", "1100110", "1101100", "1000010", 
                                          "1011100", "1001110", "1010000", "1000100", 
                                          "1001000", "1110100" };
    
          private string _sQuiteZone = "000000000";
    
          private string _sLeadTail = "101";
    
          private string _sSeparator = "01010";
    
          private string _sCountryCode = "00";
          private string _sManufacturerCode;
          private string _sProductCode;
          private string _sChecksumDigit;
    
          public Ean13( )
          {
    
          }
    
          public Ean13( string mfgNumber, string productId )
          {
              this.CountryCode = "00";
              this.ManufacturerCode = mfgNumber;
              this.ProductCode = productId;
              this.CalculateChecksumDigit( );
          }
    
          public Ean13( string countryCode, string mfgNumber, string productId )
          {
              this.CountryCode = countryCode;
              this.ManufacturerCode = mfgNumber;
              this.ProductCode = productId;
              this.CalculateChecksumDigit( );
          }
    
          public Ean13( string countryCode, string mfgNumber, string productId, string checkDigit )
          {
              this.CountryCode = countryCode;
              this.ManufacturerCode = mfgNumber;
              this.ProductCode = productId;
              this.ChecksumDigit = checkDigit;
          }
    
          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;
          }
    
    
          private string ConvertLeftPattern( string sLeft )
          {
              switch( sLeft.Substring( 0, 1 ) )
              {
                  case "0":
                      return CountryCode0( sLeft.Substring( 1 ) );
                      
                  case "1":
                      return CountryCode1( sLeft.Substring( 1 ) );
    
                  case "2":
                      return CountryCode2( sLeft.Substring( 1 ) );
    
                  case "3":
                      return CountryCode3( sLeft.Substring( 1 ) );
    
                  case "4":
                      return CountryCode4( sLeft.Substring( 1 ) );
    
                  case "5":
                      return CountryCode5( sLeft.Substring( 1 ) );
    
                  case "6":
                      return CountryCode6( sLeft.Substring( 1 ) );
    
                  case "7":
                      return CountryCode7( sLeft.Substring( 1 ) );
    
                  case "8":
                      return CountryCode8( sLeft.Substring( 1 ) );
    
                  case "9":
                      return CountryCode9( sLeft.Substring( 1 ) );
    
                  default:
                      return "";
              }
          }
    
    
          private string CountryCode0( string sLeft )
          {
              // 0 Odd Odd  Odd  Odd  Odd  Odd 
              return ConvertToDigitPatterns( sLeft, this._aOddLeft );
          }
    
    
          private string CountryCode1( string sLeft )
          {
              // 1 Odd Odd  Even Odd  Even Even 
              System.Text.StringBuilder sReturn = new StringBuilder( );
              // The two lines below could be replaced with this:
              // sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 0, 2 ), this._aOddLeft ) );
              sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 0, 1 ), this._aOddLeft ) );
              sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 1, 1 ), this._aOddLeft ) );
              sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 2, 1 ), this._aEvenLeft ) );
              sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 3, 1 ), this._aOddLeft ) );
              // The two lines below could be replaced with this:
              // sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 4, 2 ), this._aEvenLeft ) );
              sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 4, 1 ), this._aEvenLeft ) );
              sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 5, 1 ), this._aEvenLeft ) );
              return sReturn.ToString( );
          }
    
          
          private string CountryCode2( string sLeft )
          {
              // 2 Odd Odd  Even Even Odd  Even 
              System.Text.StringBuilder sReturn = new StringBuilder( );
              sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 0, 1 ), this._aOddLeft ) );
              sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 1, 1 ), this._aOddLeft ) );
              sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 2, 1 ), this._aEvenLeft ) );
              sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 3, 1 ), this._aEvenLeft ) );
              sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 4, 1 ), this._aOddLeft ) );
              sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 5, 1 ), this._aEvenLeft ) );
              return sReturn.ToString( );
          }
    
    ........
    
      }
    
        }
    }

  • #4
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,718
    Thanks
    41
    Thanked 191 Times in 190 Posts
    you would do it just how you did it there- copy the entire contents of that .cs file and paste them...
    Code:
    namespace WindowsApplication{
      public partial class Form1 : Form{
      blah blah blah 
      } // this signifies the end of one class
      // paste your ean class here
      public class ean(){
      }
    }
    BUT! since it is already seperate and in it's own namespace etc there is no need to do this... I do not know what namespace that thing is called, but all you need to do is add reference- leave it alone on the other .cs file and other namespace- there is a reason things are done this way
    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using Ean13Barcode2005;
    
    namespace WindowsFormsApplication5
    {
        public partial class Form1 : Form
        {
    ......
    You've already done it- just make sure that when you compile you have the .dll
    adding this class to the same namespace will not make the "flicker" thing go away- it will solve no problems- it could create problems if the .dll's "upgrade" and then you have to go and find how/why it changed.

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • #5
    New Coder
    Join Date
    Apr 2012
    Posts
    24
    Thanks
    4
    Thanked 0 Times in 0 Posts
    ok I think I've decided to do wut u suggested and fix the flickering caused from the custom controls I used from CodeProject and make my own control (which would take a lot of time) but atleast I'll do it right. After that, I'll just use the Ean13.cs class and it should work now that I removed those custom controls.

  • #6
    New to the CF scene
    Join Date
    Apr 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you can refer to the Google Zxing barcode. It is also an open-source barcode image library.

    Or, you can look at this EAN13 barcode generator control

  • #7
    New to the CF scene
    Join Date
    Jun 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by keepdynamic View Post
    you can refer to the Google Zxing barcode. It is also an open-source barcode image library.

    Or, you can look at this EAN13 barcode generator control
    Nice sharing. But I have never used the tools you mentioned above.

    As for myself, I used to generate EAN 13 Barcode with the help of another Barcode Generator processing SDK.

    It is just one of many but I do appreciate its simple way of processing.

    Even though I only tried its free trial package to generate barcodes and didn´t check the cost and licensing conditions, it works great for me.

    Share with you. And I will try your sharing later.

    Thanks again.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •