Compressed GUID barcode in C#

imagesI have worked with barcode today but I have the problem: I need to print on barcode a GUID. GUIDs are usually stored as 128-bit values, and are commonly displayed as 32 hexadecimal digits with groups separated by hyphens, such as {F00DFACE-FEED-DEAD-BEEF-C0FFEEDECADE}; this post is not a tutorial about GUID (You can find information on wikipedia).

The most suitable 2D barcode to hold random data, and GUIDs is probably Code128.
you need to give a string to make a Code128 barcode. However to use the typical hexadecimal string representation is too costly. That would use only 16 (2^4) values for each code instead  of the 128 (2^7) theoretically possible (see below) with Code128.

So theoretically at least a 7/4 longer barcode.
Code128 can encode the 128 characters basic ASCII set but there is a trick here. To do so, Code128 use 2 code sets (96 characters capable each): 128A and 128B (there is also a third code set for numbers). And to switch the code set as a cost! It costs 1 code. Your barcode might end up almost the same size as string encoded (The length is variable and random: it depends on how many times the code set has to be switched).
Your data must therefore be modulated by 96 for each code, and you will get the smallest guid barcode possible. See the code below. There is also the 128 modulation methods if you want to play with variable length barcodes.

I made a static class where I compress the guid before to print. The sample project with the class is on GITHUB repository

To generate the barecode I used a codeprojects project: BARCODE GENERATOR  but there are a lot of bare code generators on internet.

Maskedtextbox and SelectAll()

I had a problem with maskedit and the selectAll. I wanted that when clicked on maskedit, all text was selected. The problem had a simply solution: I had to use the SelectAll() method in the Focus Event

.
.
.
mskBox.GotFocus += new EventHandler(mskBox_GotFocus);
.
.
.
.
void mskBox_GotFocus(object sender, EventArgs e)
{
  mskBox.SelectAll();
}

But this did not run. I found this solution:
Maskedtextbox and SelectAll()

private delegate void SetMaskedTextBoxSelectAllDelegate(MaskedTextBox txtbox);

private void maskedTextBox1_Enter(object sender, EventArgs e)
{
   this.BeginInvoke(new SetMaskedTextBoxSelectAllDelegate(SetMaskedTextBoxSelectAll), new object[] { (MaskedTextBox) sender });
}

private void SetMaskedTextBoxSelectAll(MaskedTextBox txtbox)
{
   txtbox.SelectAll();
}

And this run!!!!!