Setting Code 128 Barcode Width and Height in C#

C# Code 128 Size Setting

Using Free C# source code to generate Code 128 image labels for ASP.NET Web & Windows Applications






In this C# tutorial, you will learn how to generate Code 128 barcode with your target image width and height in .NET ASP.NET, Windows applications.

  • Learn Code 128 symbol structure
  • Code 128 dimension size calcution

How to create Code 128 barcodes using C#

  1. Download .NET Code 128 Barcode Generator Suite
  2. Install C# library to create Code 128 barcodes in .NET projects
  3. Step by Step Tutorial
















OnBarcode offers explanation of how to set Code 128 image size in C#.NET. And users are entitled to adjust Code 128 barcode size using the products below.



Code 128 Structure

  • W : the width of Code 128.
  • C : the number of start, special, symbol check and stop characters plus the number of the data characters not included in D (i.e. C=3 + special char +not double-density data char)
  • X : the width of a module bar; Xmin=1 pixel
  • Q : the width of the quiet zone; Qmin=10X
  • D : the number of numeric data characters encoded in double density (Code Set C)





Setting Code 128 Barcode Size in C#

Basic information you should know

Code 128 barcode width, W (measured in pixel), including quiet zones, can be computed from the expression below:

W = 11X (C + D/2) + 2Q + 2X

Code 128 barcode height is user-defined. So you can adjust the barcode height through Top and Bottom Margin settings in C# Code 128 generator according to your applications.

how to generate barcode in rdlc report, .net barcode reader component, c# free barcode generator, c# barcode generator example, usb barcode scanner java, generate barcode in c# windows application


Three Situations for Setting Code 128 Barcode Size in C#

Setting Code 128 barcode size in C# Code 128 Generator may have three situations:

Situation 1:

If you want to create a Code 128 with a minimum X, please do as below:
  • Set the minimum value of X.
  • Set the AutoResize option to be false.
  • Customize other properties.
Eg1. Set in C# Code 128 generator:
code128.X = 4;
code128.AutoResize = false;
Other properties: default;
The generated Code 128 image is:


Situation 2:

If you want to generate a Code 128 with a fixed barcode image width (W), and try to draw maximum barcode module (X) as possible, please do as follows:
  • Set the fixed value of barcode image width (W).
  • Set the AutoResize option to be true.
  • Customize other properties.
Eg2. Set in C# Code 128 generator:
code128.BarcodeWidth = 300;
code128.BarcodeHeight = 60;
code128.AutoResize = true;
Other properties: default;
The generated Code 128 image is:

In the above Code 128 image, the bar module (X) is 3 pixel, which is the maximum bar module.


Situation 3:

If you want to generate a Code 128 with minimum X and fixed barcode image width (W), please do as below:
  • Set the values of minimum X and barcode image width (W).
  • Set the AutoResize option to be false.
  • Customize other properties.
Eg3. Set in C# Code 128 generator:
code128.X = 2;
code128.BarcodeWidth = 200;
code128.AutoResize = false;
Other properties: default;
The generated Code 128 image is:


Note that, once you have set bar module (X) value, there will be a minimum barcode image width defined by Code 128 ISO specification.

Code128 minimum barcode image width (W min) is:

= 11X (C + 2D/2) + 22X

So if your BarcodeWidth value is less than the minimum barcode width, the barcode generator component will reset BarcodeWidth value to the minimum barcode width value.

For example, you set:

code128.X = 2;
code128.BarcodeWidth = 100;
code128. Data = "1234";
code128.AutoResize = false;
Other properties: default;
Then Code 128 barcode minimum width (W min) is:
=11*2 ( 5 + 4/2 ) + 22*2      
= 198 pixel

Now your BarcodeWidth setting is 100 pixel, which is less than the minimum barcode width, the component generated code 128 image will be like this.


If your BarcodeWidth setting is 250 pixel, which is larger than the minimum barcode width (198 pixel), the generated code 128 image will be like below. And extra 51 pixel space has been added to the left and right side of barcode image.






OnBarcode is a market-leading provider of barcode imaging generator, reader controls and components for ASP.NET, Windows Forms, WPF, as well Java, Android, iOS (iPhone, iPad) across all major enterprise development platforms. We provides comprehensive tutorials and how-tos for various linear, 2d barcode information, such as C# in ASP.NET, C# .NET, C# Barcode Encoding, C# Barcode Image, VB.NET in ASP.NET, VB.NET Winforms, VB.NET Barcode Encoding. OnBarcode barcode products are supported by RasterEdge ASP.NET Document Viewer, which supports ASP.NET PDF Viewer, ASP.NET MVC Document Viewer, ASP.NET PDF Editor, MVC PDF Viewer. And provide high quality C# Convert PDF to Tiff, C# Convert PDF to Word, C# Convert PDF to HTML, C# Convert PDF to Jpeg images, and their easy and simple documents, like C# PDF SDK, C# extract text from PDF, C# Compress PDF, Print PDF in C# and C# extract image from PDF.
Terms of Use | Privacy Policy
Copyright © OnBarcode.com . All rights reserved.