RSS

Drawing (Barcode) custom labels .. !!

23 Oct

Before stating you must know these following points:-

  • Barcode according to WIKI is an optical machine-readable representation of data, which shows data about the object to which it attaches. Originally, barcodes represented data by varying the widths and spacings of parallel lines, and may be referred to as linear or 1 dimensional (1D). Later they evolved into rectangles, dots, hexagons and other geometric patterns in 2 dimensions (2D). Although 2D systems use a variety of symbols, they are generally referred to as barcodes as well. Barcodes originally were scanned by special optical scanners called barcode readers; later, scanners and interpretive software became available on devices including desktop printers and smartphones.
  • Barcode symbols are just a windows font like Tahoma, Verdana or any other font … Here we choose another font support barcode industry like (Code 39 , 3 Of 9 barcode … etc). Notice: some of supported fonts are attached with this post.
  • You have to use or import “System.Drawing” namespace.

The code:-

for (double r = double.Parse(txtTopMargin.Text); r <= (double.Parse(txtLabelHeight.Text) + double.Parse(txtHorizontalSpace.Text)) * double.Parse(txtRows.Text); r += (double.Parse(txtLabelHeight.Text) + double.Parse(txtHorizontalSpace.Text)))
{
for (double c = double.Parse(txtLeftMargin.Text); c <= (double.Parse(txtLabelWidth.Text) + double.Parse(txtVerticalSpace.Text)) * double.Parse(txtColumns.Text); c += (double.Parse(txtLabelWidth.Text) + double.Parse(txtVerticalSpace.Text)))
{
e.Graphics.DrawString(“*DevMySkills*”, new Font(“3 of 9 barcode”, 14,FontStyle.Bold), Brushes.Blue, new Point((int)c,(int)r));
e.Graphics.DrawString(“\r\n” + “Knowledge Sharing “, new Font(“Tahoma”, 10), Brushes.Red, new Point((int)c,(int)r));
}
}

  • General Notes:-
    1. txtTopMargin object represents the margin height from the top of the page or stickers roll.
    2. txtLeftMargin object represents the margin height from the left of the page or stickers roll.
    3. txtLabelHeight object represents the height of the barcode label.
    4. txtLabelWidth object represents the width of the barcode label.
    5. txtHorizontalSpace object represents the horizontal blank space between labels.
    6. txtVerticalSpace object represents the vertical blank space between labels.
    7. txtRows object represents the number of wanted rows to be printed.
    8. txtColumns object represents the number of wanted columns to be printed.
  • Special Notes:-
    1. You definitely saw the asterisk (*) character before the string “DevMySkills”. This represents the barcode separators and will not appear in the print document as real character.
    2. There are some fonts must have start/stop characters and some other not … I know that you are asking why and how … etc. But I answered: “No ifs ands or buts about it“. I’m not going to go into the history or the encoding algorithm of Code 39 or any one of barcode fonts because that’s not what this article is about. If you want to know more about those topics you can search the web and find hundreds or thousands of articles.
    3.  You must know that you are drawing with point unit … you will need to convert it if the user commit the centimeters as a general measurement unit like: each 1 cm = 28.35 points.

Download Barcode Example … .NET Framework 4.0

Download some of barcode fonts.

 
2 Comments

Posted by on October 23, 2011 in Visual Basic .NET, Visual C# . NET

 

Tags: , , , , , , , ,

2 responses to “Drawing (Barcode) custom labels .. !!

  1. Eng. Ahmed Negm

    August 7, 2012 at 11:50 AM

    Reblogged this on Develop My Skills.

     
  2. hany

    August 10, 2013 at 2:57 AM

    الرابط لا يعمل

     

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: