Quick to Generate Code 128 using C#
It is really easy to generate Code 128 using C# barcode library.
- Create a new Linear object
- Set Code 128 data message to property Data
- Set linear barcode type to Code 128 BarcodeType.CODE128
- Use method drawBarcode() to generate Code 128 and print to an image file
Linear barcode = new Linear(); barcode.Data = "Code-128"; barcode.Type = BarcodeType.CODE128; barcode.drawBarcode("C://Output//code128-sample.png");
Code 128 Barcode Data Characters Encoding using C#
Code 128 data character set
Code 128 barcode supports the following data characters
- All 128 Full ASCII characters defined in ISO/IEC 646
- Extended ASCII characters are also supported with Function Character (FNC4) used. (By default are values 128 - 255 of ISO/IEC 8859-1, Latin Alphabet 1)
- 4 non-data function characters
- 4 code set selection characters
- 3 Start characters
- 1 Stop character
Code 128 Data Code Sets in C#
Code 128 barcode has three unique data character code sets.
- Code Sets A
- Code Sets B
- Code Sets C
Each code set includes a subset of the full ASCII character set together with various auxiliary characters.
Using OnBarcode C# Code 128 generator library, you can ignore the Code 128 code set, and the library will choose the right starting code set for you.
You can set the property Type to BarcodeType.CODE128, and the library will automatically select the right code set for you.
If you want to choose the Code 128 code set manually, you can set the Type property to
Using OnBarcode C# Code 128 generator library, you can ignore the Code 128 code set, and the library will choose the right starting code set for you.
You can set the property Type to BarcodeType.CODE128, and the library will automatically select the right code set for you.
If you want to choose the Code 128 code set manually, you can set the Type property to
- BarcodeType.CODE128A for Code Set A
- BarcodeType.CODE128B for Code Set B
- BarcodeType.CODE128C for Code Set C
// Barcode symbology type. Code 128 supports types: // CODE128, CODE128A, CODE128B, CODE128C. code128.Type = BarcodeType.CODE128;
Code 128 Function characters using C#
Code 128 Function Characters (FNC) define instructions to the bar code reading device to allow for special operations
and applications.
- FNC1: It is for GS1 system. You can find more information about GS1-128 in C#
- FNC2: It is for message append.
- FNC3: It instructs the bar code reader to interpret the data from the symbol containing the FNC3 character as instructions for initialization or reprogramming of the bar code reader.
- FNC4: It is used to represent an extended character set (byte values 128 to 255 in ISO/IEC 8859-1 by default)
Using C# Code 128 barcode generator, you do not need input function characters. Our library will automatically encode them for you.
Code 128 check digit character in C#
Code 128 barcode contains a mandatory check digit (checksum) character, which is based on module 103 (mod 103).
The Code 128 check digit will not be displayed in the human readable interpretation (barcode text), and it will not be returned by the barcode decoder also.
In barcode library class Linear, the property "AddCheckSum" is not appliable for Code 128. The library will always calculate and create a check digit character before the Stop character.
The Code 128 check digit will not be displayed in the human readable interpretation (barcode text), and it will not be returned by the barcode decoder also.
In barcode library class Linear, the property "AddCheckSum" is not appliable for Code 128. The library will always calculate and create a check digit character before the Stop character.
Code 128 Barcode Human Readable Interpretation (HRI)
HRI should be printed with the Code 128 symbol barcode. Text can be printed anywhere in the area surrounding the barcode, as long as quiet zone boundaries are not violated.
C# source code to render HRI (data text) below the Code 128 symbol
C# source code to render HRI (data text) below the Code 128 symbol
Linear code128 = new Linear(); code128.Data = "Code 128 HRI"; code128.Type = BarcodeType.CODE128;
C# source code to render HRI (data text) above the Code 128 symbol.
Note: to draw and render HRI above the barcode symbol, you need set property "TextMargin" to a negative value.
Note: to draw and render HRI above the barcode symbol, you need set property "TextMargin" to a negative value.
Linear code128 = new Linear(); code128.Data = "Code 128 HRI"; code128.Type = BarcodeType.CODE128; code128.X = 1; code128.Y = 60; code128.TextMargin = -75; code128.LeftMargin = 0; code128.RightMargin = 0; code128.TopMargin = 20; code128.BottomMargin = 0;
Customize Code 128 barcode text font style
You can create, customize Code 128 barcode text label font style, font size, and text/bars space size using C# Barcode Generator library.
- Set property
AutoResizeBarcodeTextto false. You can reset text font size now. - Set property
TextFontwith the new font name, font size and font style throughFontobject. - Set property
TextMarginto set the space between Code 128 bar modules and text label.
barcode.AutoResizeBarcodeText = false; barcode.TextFont = new Font("OCR-B", 12, FontStyle.Regular); barcode.TextMargin = 0;
Remove text label from Code 128 barcode image
After removing the barcode text label, it helps save space for the barcode.
- Set property
ShowTextto false. The barcode library will render the barcode bar modules only.
barcode.ShowText = false;
Code 128 Barcode Dimension Size in C#
Using C# Code 128 barcode generator, you can apply the following barcode dimension size settings:
- UOM: Unit of measure. You can choose PIXEL, CM or INCH.
- X: Width of narrow element. The mimumum bar width is defined by the application specification
- Y: Bar module height.
- LeftMargin, RightMargin: Quiet zone. the minimum width of quiet zone is 10X.
You can view the Code 128 Barcode Size Calculator here.
A sample C# source code to set Code 128 barcode image sizes.
code128.UOM = UnitOfMeasure.PIXEL; code128.X = 2; code128.Y = 60; code128.LeftMargin = 10; code128.RightMargin = 10; code128.TopMargin = 0; code128.BottomMargin = 0;
Generate, encode GS1 data in Code 128 using C#
The GS1 system originated in the United States and was established in 1973 by the Uniform Product Code Council, known until recently as the Uniform Code Council, Inc.
Code 128 barcode symbology is a valid data carrier for GS1. To create GS1 data in Code 128, please view barcode EAN 128 / GS1-128.
Code 128 barcode symbology is a valid data carrier for GS1. To create GS1 data in Code 128, please view barcode EAN 128 / GS1-128.
Code 128 Barcode Colors Customization in C#
You can easily customize Code 128 barcode bar, space module colors and text colors using barcode library .NET properties.
You can learn more details about barcode colors, such as transparent background color, here:
How to customize, print barcode colors using C# Barcode Generator library?
- Set property
ForeColorto specify the Code 128 barcode bar modules' color. - Set property
BackColorto specify the Code 128 barcode space modules' color and background color. - Set property
TextColorto customize the Code 128 text label color.
barcode.ForeColor = Color.Red; barcode.BackColor = Color.LightBlue; barcode.TextColor = Color.Red;
You can learn more details about barcode colors, such as transparent background color, here:
How to customize, print barcode colors using C# Barcode Generator library?
Rotate Code 128 Barcode in C#
You can freely rotate and print Code 128 barcode to fit your report label using C#.
- Set property
Rotateto rotate Code 128 image. You can rotate Code 128 barcode in 0, 90, 180, 270 degrees.
barcode.Rotate = Rotate.Rotate90;
Code 128 barcode property settings in C#
.NET Barcode Generator library has provided 20+ property settings to customize the generated Code 128 barcode image.
You view the list of Code 128 barcode property settings.
Generate, encode Non-printable chars in Code 128 using C#
Sample C# source code to encode non printable chars '[CR]' (Carriage Return) in Code 128 barcode
Linear code128 = new Linear(); // encode non printable char '[CR]', between 'a' and 'b' code128.Data = "a~013bc"; code128.Type = BarcodeType.CODE128; code128.ProcessTilde = true; code128.drawBarcode("C://Output//csharp-code128-non-print.png");
Source code to create Code-128 Barcodes in C# class example
Sample C# source code: How to generate Code 128 in C# class?
Common Asked Questions
What is the barcode 128 text code?
Code 128 barcode is a high-density linear barcode symbology, which encodes digits, text, control characters, and full ASCII 128 characters.
Using C# barcode generator library, you can quickly encode, create, customize and print Code 128 barcode images in
OnBarcode.Barcode.Linear class in C# codes.
What is Code 128 used for?
Code 128 barcode is a common linear barcode type used in:
- Food and non-food industries
- Shipping and packing industry
- Health, public sector and government bodies
What is the check digit code 128?
Code 128 barcode contains a mandatory check digit (checksum) character, which is based on module 103 (mod 103).
Using C# barcode library, the generator software will automatically calculate the check sum character and insert into the Code 128 barcode in C# apps.
What is Code 128 barcode maximum length?
The Code 128 ISO standard does not define the maximum number of characters in a single Code 128 barcode.
However some Code 128 standards will provide the limits. GS1-128 has limits the maximum length of Code 128 data to 48 characters.
However some Code 128 standards will provide the limits. GS1-128 has limits the maximum length of Code 128 data to 48 characters.
How to read Code 128?
You can download and install free Code 128 barcode scanner software, or use barcode scanner device, or 3rd party apps installed on phone to read and scan the Code 128 barcodes.
OnBarcode provides C# Barcode Reader library to scan, read Code 128 and other 2d, 1d barcodes in C# app. Also you can use the OnBarcode free Code 128 barcode scanner software to decode
Code 128 barcode images.
Is Code 128 barcode better than Code 39?
Code 128 is more compact than Code 39, supporting more data to be encoded in a smaller space.
C# Barcode library allows C# developers to encoding and printing both Code 128 and Code 39 in C# class.
Summary
OnBarcode C# Barcode Generator makes it easy to generate, create Code 128 and other linear & 2d barcodes in Microsoft Visual Studio .NET projects.
OnBarcode provides multiple Code 128 Generator solutions, components and software, including Code 128 in Excel, Code 128 in Java, Code 128 in ASP.NET, Code 128 in VB.NET, Code 128 Generator.
This document is providing a detailed C# source code about generating Code 128 barcodes in C# class using C# Barcode generation component.
OnBarcode provides multiple Code 128 Generator solutions, components and software, including Code 128 in Excel, Code 128 in Java, Code 128 in ASP.NET, Code 128 in VB.NET, Code 128 Generator.
This document is providing a detailed C# source code about generating Code 128 barcodes in C# class using C# Barcode generation component.