/// <summary> /// What to do when the selection changes in the QR Code site list: /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void cmboExportSiteQR_SelectedIndexChanged(object sender, EventArgs e) { // Asbestos underpants: try { // Get the current selection of the combo box and make sure it // isn't empty: String site = (string)cmboExportSiteQR.Text; if (!String.IsNullOrEmpty(site)) { // Ask the main form to give us the site parameters for this site. // Since the main form has all the code to do this, we'll ask it // to do the dirty work. SiteParameters siteParams = caller.GetSiteParamsForQRCode(site); // Now we'll generate the text we'll embed into the QR Code. We want // this to be as compact as we can get it, so our "headings" will be // single letters. We'll start off with an identifying header so the // QR Code reader will know the format of our string. We delimite the // string with pipes, which aren't allowed in any of our fields. We // want this to match as closely to the values of the XML export file // for consistency. That means the hash engine and the character // limit fields will need some tweaking. StringBuilder sb = new StringBuilder(); sb.Append("CRYPTNOSv1|" + "S:" + siteParams.Site + "|" + "H:" + HashEngine.HashEnumStringToDisplayHash(siteParams.Hash) + "|" + "I:" + siteParams.Iterations.ToString() + "|" + "C:" + siteParams.CharTypes.ToString() + "|L:"); if (siteParams.CharLimit < 0) sb.Append("0"); else sb.Append(siteParams.CharLimit.ToString()); // Now that we've built our string, use the QRCodeWriter from ZXing to // build the QR Code image and assign the bitmap to the picture box: byteMatrix = qrCodeWriter.encode(sb.ToString(), BarcodeFormat.QR_CODE, 200, 200); pictureBox1.Image = byteMatrix.ToBitmap(); } // If the selection in the combo box wasn't useful, empty the picture box: else pictureBox1.Image = null; } // Similarly, if anything blew up, empty the picture box: catch { pictureBox1.Image = null; } }