Generate c # winform GUI with a one-dimensional code,
Recently, I saw my colleague Xiaohong doing a one-dimensional code. I felt very good, so I found an example on the Internet to play.
The following code is all online code. I did some sorting, but I forgot the source. The original author can remind me, thank you. First of all, the relevant knowledge of one dimension code can first Baidu: http://baike.baidu.com/link? Url = example _ the description is clear. Just read it.
Description: Code39 is used in this example. The interface is as follows. If you need this code, go to the 360 cloud disk right: http://yunpan.cn/cKICBPBrk7xxh extract code 0fe0 but considering some just want to see the process of students, I Will paste the main code below
/// <Summary> /// generates a Bitmap for the bar code to customize the bar code height, custom text alignment style /// </summary> /// <param name = "sourceCode"> </param> /// <param name = "barCodeHeight"> </ param> /// <param name = "sf"> </param> // <returns> </returns> public Bitmap GetCode39 (string sourceCode, int barCodeHeight, StringFormat sf) {BarCodeText = sourceCode. toUpper (); int leftMargin = 5; int topMargin = 0; int thickLength = 2; int narrowLength = 1; int in TSourceLength = sourceCode. length; string strEncode = "010010100"; // Add the start code "*". var font = new System. drawing. font ("Segoe UI", 5); string AlphaBet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ -. $/+ % * "; string [] Code39 = {/* 0 */" 000110100 ",/* 1 */" 100100001 ",/* 2 */" 001100001 ", /* 3 */"101100000",/* 4 */"000110001",/* 5 */"100110000",/* 6 */"001110000 ", /* 7 */"000100101",/* 8 */"100100100",/* 9 */"001100100",/* A */"100001001",/* B */"001001001 ", /* C */"101001000",/* D */"000011001",/* E */"100011000",/* F */"001011000 ", /* G */"000001101",/* H */"100001100",/* I */"001001100",/* J */"000011100 ", /* K */"100000011",/* L */"001000011",/* M */"101000010",/* N */"000010011 ", /* O */"100010010",/* P */"001010010",/* Q */ "000000111",/* R */"100000110",/* S */"001000110",/* T */"000010110",/* U */"110000001 ", /* V */"011000001",/* W */"111000000",/* X */"010010001",/* Y */"110010000 ", /* Z */"011010000",/*-*/"010000101 ",/*. */"110000100",/* ''' */"011000100",/* $*/"010101000",/*/"010100010 ", /* + */"010001010",/* % */"000101010",/***/"010010100"}; sourceCode = SourceCode. toUpper (); Bitmap objBitmap = new Bitmap (thickLength * 3 + narrowLength * 7) * (intSourceLength + 2) + (leftMargin * 2 ), barCodeHeight + (topMargin * 2); Graphics objGraphics = Graphics. fromImage (objBitmap); objGraphics. fillRectangle (Brushes. white, 0, 0, objBitmap. width, objBitmap. height); for (int I = 0; I <intSourceLength; I ++) {// if (AlphaBet. indexOf (sourceCode [I]) = -1 | sourceCode [I] = '*') {objGraphics. drawString ("Invalid Bar Code", SystemFonts. defaultFont, Brushes. red, leftMargin, topMargin); return objBitmap;} // encode strEncode = string. format ("{0} 0 {1}", strEncode, Code39 [AlphaBet. indexOf (sourceCode [I]);} strEncode = string. format ("{0} 0010010100", strEncode); // Add the end code "*" int intEncodeLength = strEncode. length; int intBarWidth; for (int I = 0; I <IntEncodeLength; I ++) // draw Code39 barcode {intBarWidth = strEncode [I] = '1 '? ThickLength: narrowLength; objGraphics. FillRectangle (I % 2 = 0? Brushes. black: Brushes. white, leftMargin, topMargin, intBarWidth, barCodeHeight); leftMargin + = intBarWidth;} // draw the plaintext Font barCodeTextFont = new Font ("", 10F ); rectangleF rect = new RectangleF (2, barCodeHeight-20, objBitmap. width-4, 20); objGraphics. fillRectangle (Brushes. white, rect); // text alignment objGraphics. drawString (BarCodeText, barCodeTextFont, Brushes. black, rect, sf); return objBitmap ;}
Well, if you are interested, you can see how to implement the one-dimensional code you want.
Note: I am a beginner, and I have never thought of anything in this article. Please forgive me.