Barcode
Namespace: Wisej.Web.Ext.Barcode
Assembly: Wisej.Web.Ext.Barcode (4.1.0.0)
Represents a barcode widget supporting several formats.
- C#
- VB.NET
public class Barcode : Control
Public Class Barcode
Inherits Control
The value encoded in the barcode is the Text of the control. The barcode is drawn on the server with the ZXing.NET library, sized to fill the control minus its Padding, and uses the ForeColor, BackColor and Font of the control.
Example:
The following example shows a QR code with a link and a Code 128 barcode with a product number:
var qrCode = new Barcode
{
BarcodeType = BarcodeType.QR,
Text = "https://wisej.com",
ShowLabel = false,
Size = new Size(150, 150)
};
var productCode = new Barcode
{
BarcodeType = BarcodeType.Code_128,
Text = "PRD-004521",
Size = new Size(250, 80),
Location = new Point(0, 160)
};
this.Controls.AddRange(new Control[] { qrCode, productCode });
Constructors
Barcode()
Creates a new instance of the Barcode control.
The new control shows a Code 39 barcode with its label, uses the Arial 10pt font for the label and has a default size of 100 x 40 pixels. It can't receive the focus.
Example:
var barcode = new Barcode();
barcode.BarcodeType = BarcodeType.EAN_13;
barcode.Text = "5901234123457";
barcode.Dock = DockStyle.Top;
barcode.Height = 100;
this.Controls.Add(barcode);
Properties
BarcodeType
BarcodeType: Returns or sets the barcode symbology to use.
BorderStyle
BorderStyle: Indicates the border style for the control. (Default: None)
Value: One of the BorderStyle values. The default is BorderStyle.None.
DefaultSize
Size: The default Size of the control.
ShowLabel
Boolean: Shows or hides the barcode label. (Default: True)
VerticalOffset
Int32: The number of pixels to offset from the bottom of the barcode. (Default: 0)
Methods
DrawBarCode()
Draws the barcode and returns the image object.
Returns: Image. An Image with the barcode, or null if nothing could be drawn.
The image uses the current BarcodeType, ShowLabel, VerticalOffset, size, padding, colors and font of the control, and encodes the Text of the control. The caller is responsible for disposing the returned image. An exception is thrown when the text can't be encoded with the selected BarcodeType, for example letters in an EAN_13 barcode.
Example:
The following example saves the barcode as a PNG file and downloads it to the browser:
private void buttonDownload_Click(object sender, EventArgs e)
{
using (var image = this.barcode1.DrawBarCode())
using (var stream = new MemoryStream())
{
image.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
stream.Position = 0;
Application.Download(stream, "barcode.png");
}
}
OnWebRender(config)
Renders the client component.
| Parameter | Type | Description |
|---|---|---|
| config | Object | Dynamic configuration object. |