Writing Windows Applications

COMPONENT SELECTION

For native Windows applications, you can choose either the Barcode component or BarcodeControl.

Barcode is a System.ComponentModel.Component and can be used easily anywhere in your code. It does not have a user interface at design time or at run time.

BarcodeControl is a System.Windows.Forms.Control and can be used in Control containers, like a Windows Form. It has a user interface that simply displays a barcode. At design time, the barcode changes as you select the control properties. If need be, you may choose to hide the control at run time. BarcodeControl is implemented as a wrappper around Barcode.

USING THE COMPONENTS

Both Barcode and BarcodeControl expose the same set of properties and methods. So both are used the same way once initialized. If you did not add Barcode to your Form at design time, you can create an instance of it at run time by calling one of its constructors.

Once you have an instance of either Barcode or BarcodeControl, you can set the barcode type using the BarcodeType property. Then you can set the barcode Data. That's it for the essentials. You could further set other properties like, color, rotation, styles, etc.

The next thing you would do is actually draw the barcode using the Draw method, to a Graphics object representing the screen or a printer. You may also call the MakeImage or SaveImage to directly generate an image in any of of the .Net supported image formats like GIF, JPEG, PNG, BMP, etc.

EXAMPLE

The Barcode .Net related code below is minimal and highlighted in bold. First add a Barcode or BarcodeControl named barcode1 to a Windows Form. Then add the following event handler. A barcode will be displayed on your form.
protected override void OnPaint(PaintEventArgs e)
{
    base.OnPaint(e);
    // unit of measure is LOENGLISH or 0.01 inch:
    RectangleF rect = new RectangleF(40.0f, 80.0f, 180.0f, 60.0f);
    barcode1.Draw(e.Graphics, rect, GraphicsUnit.Inch, 0.01f,
        BarcodeDrawFlags.PaintWholeRect, null);
}
You can also print a barcode on your printer. Add a button named PrintButton to your form and then add the following two event handlers to your form code. Then clicking the button will send a barcode to your printer.
private void pd_PrintPage(object sender, PrintPageEventArgs e) 
{
    // unit of measure is LOENGLISH or 0.01 inch:
    RectangleF rect = new RectangleF(40.0f, 80.0f, 180.0f, 60.0f);
    barcode1.Draw(e.Graphics, rect, GraphicsUnit.Inch, 0.01f, 0, null);
    e.HasMorePages = false;
}

private void ButtonPrint_Click(object sender, System.EventArgs e)
{
    PrintDocument pd = new PrintDocument();
    pd.PrintPage += new PrintPageEventHandler(this.pd_PrintPage);

    PrintDialog dlg = new PrintDialog() ;
    dlg.Document = pd;
    DialogResult result = dlg.ShowDialog();

    if (result == DialogResult.OK) 
    {
        pd.Print();
    }
}