Generating Barcode Code 128 in .NET is one of the functions in OnBarcode's
.NET Barcode Generators, which supports creating & printing Code-128 and 30+ other linear & 2D bar codes for C#, VB.NET & ASP.NET applications.
OnBarcode develops several .NET Barcode Generation components for different .NET development environments:
.NET Code 128 Generator encodes:
- all 128 characters of ASCII
- values 128-255 in accordance with ISO 8859-1. There are referred to as extended ASCII.
Generating barcode Code-128 in
C# Class example (
C# Code 128 Generator Complete Demo Source Code):
Generating barcode Code-128 in
VB.NET Class example (
VB.NET Code 128 Generator Complete Demo Source Code):
Category |
Properties |
Value |
Comments |
Basic
|
Property: Data
URL: DATA
|
Type: string
Default: "12345"
|
Barcode value to encode
Code 128 Valid Data Char Set:
- all 128 ASCII characters (Char from 0 to 127)
|
Property: Type
URL: TYPE
|
Type: BarcodeType
Default: CODE128 (7)
|
Linear barcode symbology type.
Set the value to BarcodeType.CODE128 or BarcodeType.CODE128A or BarcodeType.CODE128B or BarcodeType.CODE128C.
Code 128 type values are BarcodeType.CODE128 (7), BarcodeType.CODE128A (8), BarcodeType.CODE128B (9), BarcodeType.CODE128C (10).
|
Property: AddCheckSum
URL: ADD-CHECK-SUM
|
Type: bool
Default: false
|
AddCheckSum property is not applied here. |
|
Code 128 Special |
Property: ProcessTilde
URL: PROCESS-TILDE
|
Type: bool
Default: false
|
Set the ProcessTilde property to true, if you want use the tilde character "~"
to specify special characters in the input data.
- 1-byte character: ~0dd/~1dd/~2dd (character value from 000 ~ 255); ASCII character '~' is presented by ~126
Strings from "~256" to "~299" are unused
- 2-byte character (Unicode): ~6ddddd (character value from 00000 ~ 65535)
Strings from "~665536" to "~699999" are unused
|
|
Barcode Size Related |
Property: AutoResize
URL: AUTO-RESIZE
|
Type: bool
Default: false
|
Auto resize the generated barcode image
|
Property: BarAlignment
URL: BAR-ALIGNMENT
|
Type: int
Default: 1 (center)
|
Barcode horizontal alignment inside the image. 0: left, 1: center, 2: right. |
Property: UOM
URL: UOM
|
Type: UnitOfMeasure
Default: PIXEL (0)
|
Unit of meature for all size related settings in the library.
Valid values:
- UnitOfMeasure.PIXEL (0)
- UnitOfMeasure.CM (1)
- UnitOfMeasure.INCH (2)
|
Property: X
URL: X
|
Type: float
Default: 1
|
Width of barcode bar module (narrow bar), default is 1 pixel |
Property: Y
URL: Y
|
Type: float
Default: 60
|
Height of barcode bar module, default is 60 pixel |
Property: BarcodeWidth
URL: BARCODE-WIDTH
|
Type: float
Default: 0
|
Barcode image width.
If barcodeWidth setting is smaller than the barcode required minimum width, the library will automatically reset to barcode minimum width. |
Property: BarcodeHeight
URL: BARCODE-HEIGHT
|
Type: float
Default: 0
|
Barcode image height.
If barcodeHeight setting is smaller than the barcode required minimum height, the library will automatically reset to barcode minimum height. |
Property: LeftMargin
URL: LEFT-MARGIN
|
Type: float
Default: 0
|
Barcode image left margin size. |
Property: RightMargin
URL: RIGHT-MARGIN
|
Type: float
Default: 0
|
Barcode image right margin size. |
Property: TopMargin
URL: TOP-MARGIN
|
Type: float
Default: 0
|
Barcode image top margin size. |
Property: BottomMargin
URL: BOTTOM-MARGIN
|
Type: float
Default: 0
|
Barcode image bottom margin size. |
Property: Resolution
URL: RESOLUTION
|
Type: int
Default: 72
|
Barcode image resolution in DPI (Dots per inch). |
Property: Rotate
URL: ROTATE
|
Type: Rotate
Default: Rotate0 (0)
|
Valid values:
- Rotate.Rotate0 (0)
- Rotate.Rotate90 (1)
- Rotate.Rotate180 (2)
- Rotate.Rotate270 (3)
|
|
Barcode Colors |
Property: BackColor
URL: BACK-COLOR
|
Type: Color
Default: white
|
Barcode image background color |
Property: ForeColor
URL: FORE-COLOR
|
Type: Color
Default: black
|
Barcode image foreground color
|
|
Font Style |
Property: ShowText
URL: SHOW-TEXT
|
Type: bool
Default: true
|
If true, display barcode data text under the barcode, otherwise do not display. |
Property: TextFont
URL: TEXT-FONT
|
Type: Font
Default: new Font("Arial", 9f, FontStyle.Regular)
|
Barcode text font style.
In ASP.NET web streaming, using the url paramter in the following format:
&TEXT-FONT=Arial|9|regular
|
Property: TextMargin
URL: TEXT-MARGIN
|
Type: float
Default: 6
|
Space between barcode and barcode data text, default is 6 pixel |
Property: TextColor
URL: TEXT-COLOR
|
Type: Color
Default: black
|
Barcode text color
|
|
Image Format |
Property: Format
URL: FORMAT
|
Type: ImageFormat
Default: Png
|
Barcode image encoding type. |
|
Methods |
// generate barcode and encode to image file
public void drawBarcode(string filename)
// generate barcode and paint on Graphics object
public void drawBarcode(Graphics graphics)
// generate barcode and paint on Bitmap object
public Bitmap drawBarcode()
// generate barcode and paint on Stream object
public void drawBarcode(Stream fileStream)
// generate barcode and paint on byte[] object
public byte[] drawBarcodeAsBytes()
|
|
In WebStream query string, please use int value for Enums, "true" and "false" for bool.
|