日期:2014-05-18 浏览次数:20608 次
protected void Page_Load(object sender, EventArgs e) { string a = CreateBarCode("4242", 50, 3, true); Response.Write(a); } public string CreateBarCode(string text, int height, int width, bool showText) { string strTemp = text.ToLower(); //替换各个字符 strTemp = strTemp.Replace("0", "_|_|__||_||_|"); strTemp = strTemp.Replace("1", "_||_|__|_|_||"); strTemp = strTemp.Replace("_", "<span style='height:" + height + ";width:" + width + ";background:#FFFFFF;'></span>"); strTemp = strTemp.Replace("|", "<span style='height:" + height + ";width:" + width + ";background:#000000;'></span>"); if (showText) { return strTemp + "<br/>" + text; } else { return strTemp; } }
Literal1.Text = CreateBarCode("leaves", 50, 3, true); Response.Write(Literal1.Text);