Menu

Barcode .NET Methods


Barcodes.Barcode Namespace

BarcodeControl Class
Barcodes.Barcode.dll assembly
 
About Method
Returns an about information.

Syntax
string About()
Return Value
String that specifies an about information.



SaveToImageFile Method
Saves the image of the barcode to a file.

Syntax
ErrorCodes SaveToImageFile(double cx, double cy, string sFileName, 
   int lRes, Dimensions dm)
Parameters
cxA double that defines the barcode picture width.
cyA double that defines the barcode picture height.
sFileNameA string expression defining the file name.
lResA integer value that sets the picture resolution.
dmThe Dimensions value. This value defines the units that should be used to specify cx and cy. See remarks.
Return Value
ErrorCodes
Remarks
The format the file will be saved in depends on the extension of the file name For example, if you specify sFileName as "img1.jpg", the barcode will be saved as JPEG.
The following extensions can be used - "wmf", "emf", "bmp", "jpg", "jpeg", "gif", "tiff" and "png".

If the size of an image (cx, cy) is not specified in pixels, its actual size will be calculated using the specified picture resolution - lRes.
Examples
/* 1.
Save the image to a file of the JPEG format. The size of the image will be 200x100 pixels with the resolution of 96 dpi.*/

barcodeControl1.SaveToImageFile( 300, 100, "c:\\barcode.jpg", 0, Barcodes.Barcode.Dimensions.dmPixels );

/* 2.
Save the image to a file of the JPEG format. The size of the image will be 50x25 millimeters with the resolution of 300 dpi.*/

barcodeControl1.SaveToImageFile( 50, 25, "c:\\barcode.jpg", 300, Barcodes.Barcode.Dimensions.dmMM ) ;

/* 3.
Calculate the required barcode width. See GetBarcodeWidth method.*/

double barWidth;
barcodeControl1.GetBarcodeWidth( 3, 96, 96, Dimensions.dmPixels, Dimensions.dmPixels, out barWidth );
// Save the image to a file of the JPEG format. The barcode will have the x-dimension of 3 pixels and the height of 100 pixels.
barcodeControl1.SaveToImageFile( barWidth, 100, "c:\\barcode.jpg", 96, Dimensions.dmPixels ) ;



DrawBarcodeToSize Method
Draws the barcode in the device context or Graphics object. You can use either printer or screen.

Syntax
ErrorCodes DrawBarcodeToSize(double x, double y, double cx, double cy, Dimensions dm, IntPtr hDC)

ErrorCodes DrawBarcodeToSize(double x, double y, double cx, double cy, Dimensions dm, Graphics gr)

Parameters

XA double value that defines the X coordinate of the barcode.
YA double value that defines the Y coordinate of the barcode.
CXA double that defines the barcode width.
CYA double that defines the barcode height.
dmA Dimensions value. This value defines the units that should be used to specify cx and cy.
hDCThe handle of the device context where the barcode will be drawn.
gr A Graphics object.

Return Value

ErrorCodes
Examples
// Draw a barcode to a screen.
Graphics gr = this.CreateGraphics();
barcodeControl1.DrawBarcodeToSize( 350, 10, 250, 100, Barcodes.Barcode.Dimensions.dmPixels, gr );


// Print a barcode
// The OnPrintBarcodePage event is raised for each page to be printed.
private void OnPrintBarcodePage(object sender, PrintPageEventArgs ev)
{
   double wMM;
   barcodeControl1.GetBarcodeWidth( 0.5, (int)ev.Graphics.DpiX, (int)ev.Graphics.DpiY,
      Barcodes.Barcode.Dimensions.dmMM, Barcodes.Barcode.Dimensions.dmMM, out wMM );


   // print a barcode to X=10 mm, Y=10 mm, X-Dimension=0.5 mm, HEIGHT=25 mm
   barcodeControl1.DrawBarcodeToSize(10, 10, 25, wMM, Barcodes.Barcode.Dimensions.dmMM,
      ev.Graphics );
}





CopyToClipboard Method
Copies the image of the barcode onto the clipboard. After that you can insert this image into your program using Ctrl+V or the Paste menu item.

Syntax
ErrorCodes CopyToClipboard(int cx, int cy)
Parameters
cxAn integer value that defines the barcode picture width
cyAn integer value that defines the barcode picture height
Return Value
ErrorCodes



GetBarcodeWidth Method
This method calculate the width that the barcode must have in order to get the necessary x-dimension.

require a barcode width

Syntax
ErrorCodes GetBarcodeWidth(double lModule, int xRes, int yRes, Dimensions dmIn, Dimensions dmOut, out double width)

Parameters

lModuleThis double value that defines the necessary x-dimension.
xResA long value that defines the resolution (in dpi) along x axis.
yResA long value that defines the resolution (in dpi) along y axis.
dmInA Dimensions value. This value defines the units that should be used to specify lModule.
dmOutA Dimensions value. This value defines the units that should be used to specify the width.

Return Value

ErrorCodes
Example
double wMM;
barcodeControl1.GetBarcodeWidth( 0.5, (int)ev.Graphics.DpiX, (int)ev.Graphics.DpiY, Dimensions.dmMM, Dimensions.dmMM, out wMM );