private void btnLoadPrinters_Click(object sender, EventArgs e) { IniFile ini = new IniFile(iniFilePath); try { cmbPrinters.Items.Clear(); string[] dvs = ini.ReadSection("Printers"); foreach (string dv in dvs) { if (dv == null) { continue; } string[] keys = dv.Split('='); if (keys == null) { continue; } if (keys.ToString() == string.Empty) { continue; } string key = keys[0]; //string[] dvItem = dv.Split('='); //if (dvItem == null) // continue; //ComboboxItem item = new ComboboxItem(); //item.Text = dvItem[0]; //item.Value = dvItem[1]; cmbPrinters.Items.Add(key); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void setAktifPrinterByIndex(int index) { IniFile ini = new IniFile(iniFilePath); try { int px = -1; string printername = ""; string[] dvs = ini.ReadSection("Printers"); foreach (string dv in dvs) { if (dv == null) { continue; } string[] keys = dv.Split('='); if (keys == null) { continue; } if (keys.ToString() == string.Empty) { continue; } string key = keys[0]; px++; if (px == index) { printername = key; aktifPrinter.name = printername; string interval = ini.ReadValue(printername, "ShutdownInterval"); if (interval != null) { if (interval != string.Empty) { aktifPrinter.interval = Convert.ToInt32(interval); } } string printCount = ini.ReadValue(printername, "PrintCount"); if (printCount != null) { if (printCount != string.Empty) { aktifPrinter.printCount = Convert.ToInt32(printCount); } } string printNameIE = printername + "IE"; string margin_bottom = ini.ReadValue(printNameIE, "margin_bottom"); string margin_left = ini.ReadValue(printNameIE, "margin_left"); string margin_right = ini.ReadValue(printNameIE, "margin_right"); string margin_top = ini.ReadValue(printNameIE, "margin_top"); string keyName = @"Software\Microsoft\Internet Explorer\PageSetup"; using (RegistryKey ekey = Registry.CurrentUser.OpenSubKey(keyName, true)) { if (ekey != null) { ekey.SetValue("margin_bottom", margin_bottom); ekey.SetValue("margin_left", margin_left); ekey.SetValue("margin_right", margin_right); ekey.SetValue("margin_top", margin_top); } } } } } catch { } }