Home > .NET Barcode > C# Barcode Generation Guide > C# Code 39 Generator for .NET, ASP.NET


C# Code 39 Generator Library for .NET

How to Generate Code 39 Linear Barcodes in .NET applications in Visual C#
  • Integrate Code 39 linear barcode encoding features into Visual Studio .NET Framework 2.0 or greater
  • Generate and draw Code 39 barcodes for .NET applications using Visual C# class library
  • Fully compiled in Visual C#, compatible with Visual Studio 2005, 2008, 2010, etc
  • Easily generate and print barcode Code 39 for .NET Windows Forms and ASP.NET Web Form
  • Create and insert Code 39 1D barcode images on .NET reportings, like Crystal Reports, Reporting Services and RDLC Local Reports
  • Generate high print-quality Code 39 barcodes in memory and in image file formats
  • Generated Code 39 barcode images that comply with the latest ISO / IEC 16388 specification
  • Provide free C# demo code to customize Code 39 barcode shape, size, color easily
  • Provide multiple license options for this professional C# Barcode Generator .NET Control

Code 39 Barcode Introduction

Linear Barcode Code 39 is also known as Alpha39, Code 3 of 9, Code 3/9, Type 39, USS Code 39, or USD-3.
Compatibility: Code 39 barcodes generated by this .NET Barcode Generator SDK comply with ISO / IEC 16388 (2nd edition 2007-05-15) bar code specification.
Code 39 barcode is a linear barcode symbology developed by Dr. David Allais and Ray Stevens of Intermec in 1974. Nowadays, Code 39 is widely adopted in Non-retail environments, U.S. Government and military use and Health Industry Bar Code Council (HIBCC)).
Code 39 bar code is able to encode 43 characters: A-Z, 0-9, 7 special chars [-(Dash), $(Dollar), %(Percentage), (Space), .(Point), /(Slash), +(Plus)], and 1 start/stop characters (*).
For more Code 39 information, please see .NET Code 39 Barcode Introduction




Quick to create Code 39 barcode in C# class

Using C# Barcode Generator library, you can quickly create and print Code 39 barcode images in C# class.
  • Create a new Linear object
  • Choose the encoding barcode format in property Type as BarcodeType.CODE39
  • Enter the Code 39 encoding text in property Data
  • Print the Code 39 barcode to a PNG image file using method drawBarcode()
Linear barcode = new Linear();
barcode.Type = BarcodeType.CODE39;
barcode.Data = "CODE39";
barcode.drawBarcode("C://BarcodeLib//csharp-code39-sample-image.png");





Code 39 Barcode Text Encoding using C#

Code 39 barcode supports two data encoding mode, standard mode and extended mode.

Code 39 Standard mode encodes
  • Numbers: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
  • Uppercase letters: (A - Z)
  • Special characters: - (Dash), $ (Dollar), % (Percentage), (Space), . (Point), / (Slash), + (Plus)
  • Start/Stop character: *
Code 39 extended mode encodes
  • Full 128 ASCII characters
BarcodeLib C# Barcode library supports both Code 39 standard mode and extended mode barcode generation in C# ASP.NET, WinForms, WPF applications.


Code 39 standard mode

To create Code 39 barcode with standard mode, you can simply enter the supported characters in property Data in C# source code.
barcode.Data = "CODE39";


Code 39 full ASCII mode

ASCII table contains 128 characters. There are 95 printable characters and 33 control characters (non-priting chars).

To print Code 39 with 95 printing chars, you can easily enter the encoding text to the Data property in C# code.
  • Choose data type property Type as BarcodeType.CODE39EX to create Code 39 barcode with extended mode.
  • Enter the printing ASCII chars to property Data
Linear barcode = new Linear();
barcode.Type = BarcodeType.CODE39EX;
barcode.Data = "Code-39";
barcode.drawBarcode("C://BarcodeLib//csharp-code39-full-ascii.png");



If you need create Code 39 barcode with ASCII control chars encoded, you need pass control char's ASCII integer value to the property Data.
  • Enable property ProcessTilde to true. The barcode library will handle the special character with integer value provided.
  • Convert each ASCII control character to the following format: "~ddd". Here "ddd" is the ASCII integer value in 3 digits.
  • Insert the converted ASCII control char string to the Code 39 encoding data, and pass to property Data
Linear barcode = new Linear();
barcode.Type = BarcodeType.CODE39EX;
barcode.ProcessTilde = true;
barcode.Data = "Code~01339";
barcode.drawBarcode("C://BarcodeLib//csharp-code39-ascii-non-printing-char.png");



Code 39 apply check characters

By default, the Code 39 will not include check characters. If you need, you can apply check character using C# Barcode Generator library.
  • Enable property AddCheckSum to true to apply Code 39 check character.
  • Enable property ShowCheckSumChar to true to print checksum character to the Code 39 text label.
Linear barcode = new Linear();
barcode.Type = BarcodeType.CODE39;
barcode.Data = "CODE39";
barcode.AddCheckSum = true;
barcode.ShowCheckSumChar = true;
barcode.drawBarcode("C://BarcodeLib//csharp-code39-apply-check-char.png");



Code 39 start / stop characters

Code 39 barcode uses asterisk character (*) as Start and Stop characters. In the Code 39 barcode text label (barcode human-readable interpretation), you can choose to print or hide the start/stop chars.




Customize Code 39 barcode width & height using C#

You can quickly create and customize the Code 39 barcode with specified image width and height using C# Barcode library.
  • Set the specified image width value in pixel to property ImageWidth
  • Set the specified image height value in pixel to property ImageHeight
Linear barcode = new Linear();
barcode.Type = BarcodeType.CODE39;
barcode.Data = "CODE39";
barcode.ImageWidth = 300;
barcode.ImageHeight = 200;
barcode.drawBarcode("C://BarcodeLib//csharp-code39-image-width-height.png");



BarcodeLib C# Barcode Generation SDK library supports more dynamic barcode size settings. You can view more details here: How to create barcode with specified size using C# Barcode library?




Customize Code 39 barcode text label using C#

BarcodeLib C# Barcode Generator library supports multiple options to customize linear / 1d barcode text label. Here we will learn how to customize the Code 39 barcode text
  • Print or hide Code 39 start / stop characters
  • Print or hide Code 39 check character
  • Print or hide Code 39 text label
  • Customize the Code 39 text font style, text color, and font size


Code 39 print, hide start / stop chars

You can hide the Code 39 barcode start, stop characters through property ShowStartStopChar in C# source code.
Linear barcode = new Linear();
barcode.Type = BarcodeType.CODE39;
barcode.Data = "CODE39";
barcode.ShowStartStopChar = false;
barcode.drawBarcode("C://BarcodeLib//csharp-code39-hide-start-stop-chars.png");



Code 39 print, hide check characters

When you apply Code 39 barcode checksum character, you can hide the check character in the Code 39 text label.
  • Set property AddCheckSum to true to calculate and apply the Code 39 checksum character.
  • Set property ShowCheckSumChar to false to hide the check character in the Code 39 barcode text label.
Linear barcode = new Linear();
barcode.Type = BarcodeType.CODE39;
barcode.Data = "CODE39";
barcode.AddCheckSum = true;
barcode.ShowCheckSumChar = false;
barcode.drawBarcode("C://BarcodeLib//csharp-code39-apply-hide-check-char.png");



Code 39 print, hide Code 39 text

Sometimes you need hide Code 39 barcode text label to save the printing space. You can set the property ShowText to false in the C# source code using C# Barcode library.

Linear barcode = new Linear();
barcode.Type = BarcodeType.CODE39;
barcode.Data = "CODE39";
barcode.ShowText = false;
barcode.drawBarcode("C://BarcodeLib//csharp-code39-hide-text.png");

Generated Code 39 barcode image without text label printed


Code 39 text style, color, font size

Using C# Barcode generation library, you can freely customize the printed Code 39 barcode text styles in C# application.
  • Set property TextFont to specify the text font family, font style. (Note: you cannot change the text size here. View the next demo code to resize Code 39 text size)
  • Set property TextFontColor to change the Code 39 text color in RGB.
Linear barcode = new Linear();
barcode.Type = BarcodeType.CODE39;
barcode.Data = "CODE39";
barcode.TextFont = new Font("OCR-B", 16, FontStyle.Bold);
barcode.TextFontColor = Color.Red;
barcode.drawBarcode("C://BarcodeLib//csharp-code39-text-style.png");



The C# source code below shows how to change the Code 39 barcode text default size.
  • Set property ResizeText to false to disable 1d barcode text auto-resize by barcode library.
  • Specify the target font size in property TextFont
Linear barcode = new Linear();
barcode.Type = BarcodeType.CODE39;
barcode.Data = "CODE39";
barcode.ResizeText = false;
barcode.TextFont = new Font("OCR-B", 16);
barcode.drawBarcode("C://BarcodeLib//csharp-code39-text-size.png");





Advanced Code 39 Barcode Options using C#



Code 39 wide bar vs Narrow bar ratio

In Code 39 barcode, you can specify the Code 39 wide bar vs narrow bar ratio (N). C# Barcode Generator library will set the N value as 2.0 by default. You can set the value from 2.0 to 3.0 inclusive.
Linear barcode = new Linear();
barcode.Type = BarcodeType.CODE39;
barcode.Data = "CODE39";
barcode.N = 3;
barcode.drawBarcode("C://BarcodeLib//csharp-code39-wide-narrow-bar-ratio.png");



Code 39 barcode intercharacter space

Width of intercharacter gap:
  • The minimum gap is equal to X (the narrow bar width)
  • The maximum: for X < 0.287mm, is 5.3X; for X >= 0.287mm, is 1.52mm or 3X, whichever is greater.
You can set the Code 39 intercharacter gap width through property InterGap.
Linear barcode = new Linear();
barcode.Type = BarcodeType.CODE39;
barcode.Data = "CODE39";
barcode.InterGap = 2;
barcode.drawBarcode("C://BarcodeLib//csharp-code39-intercharacter-space.png");





How to Create Code 39 in C# ASP.NET Applications?

With this C# Code 39 generator component, you can stream Code 39 barcode images in ASP.NET in two ways.
  1. Method 1: The simplest way for Code 39 barcode generation is through BarcodeLib Buildin ASP.NET Barcode Application.
    • Unzip the downloaded evaluation package, and copy barcode folder and its contents to your IIS folder, eg. C:\inetpub.
    • Create a new virtual directory in your IIS, name it "barcode", and connect it to the above "barcode" folder in inetpub.
    • Restart IIS for a barcoding test.
    • To test your installation, open your web browser and navigate to:
      http://YourDomain:port/barcode/linear.aspx?Type=7&Data=CODE39-39393939&LeftMargin=8&RightMargin=8
      For further Code 39 barcode setting, please view more web stream Code 39 URL parameters here: Code 39 .NET Generator DLL Property Settings.
    • To insert this Code 39 image in your aspx or html page, simply pass the url to IMG tag or src value.
      For example:
      <img src=http://YourDomain:port/barcode/linear.aspx?Type=7&Data=CODE39-39393939&LeftMargin=8&RightMargin=8 />
      This method will not generate any barcode images in your IIS server side.
  2. Method 2: Another method is to generate Code 39 barcodes through ASP.NET web form controller.
    • Intall ASP.NET barcode controller to your barcoding project by adding reference.
    • Add barcode library to your Visual Studio toolbox.
    • Open your unzipped trial package, and copy files "linear.aspx", "linear.aspx.cs" to the aspx page, in which you will be generating Code 39 images.
    • Now you can drag LinearASPNET to your ASP.NET web site, and change Code 39 settings through properties window on the right or use above free C# source code.
    • Debug and you will see the Code 39 barcode generated on your aspx pages.




How to Generate Code 39 in C# WinForms?

  1. Add reference to BarcodeLib.Barcode.WinForms.dll to your barcoding project.
  2. Add BarcodeLib.Barcode.WinForms.dll to your Visual Studio Toolbox.
  3. Now please drag the LinearWinForm to your windows form or use above free C# source code, and a Code 39 barcode is generated.




Supported Linear & 2D Barcode Formats

C# 1D Barcode Generation:
C# 2D Barcode Generation:
C# Barcode SDK Generates 1D (Linear) Barcodes: Codabar, Code 11, Code 2 of 5, Code 39, Code 93, EAN-8, EAN-13, Interleaved 2 of 5, ITF-14 (UPC Shipping Container Symbol), Code 128, EAN 128/GS1 128, MSI Plessey, Intelligent Mail, Planet, Postnet, RM4SCC (British Royal Mail), UPC-A, UPC-E.
C# Barcode SDK Generates 2D (Matrix) Barcodes: Data Matrix, PDF 417, QR Code.