Esempio n. 1
0
 private void comboPrinter_EnabledChanged(object sender, EventArgs e)
 {
     for (int i = comboPrinter.Items.Count - 1; i >= 0; i--)
     {
         if (typeof(PrinterComboItem) == comboPrinter.Items[i].GetType())
         {
             PrinterComboItem item = (PrinterComboItem)comboPrinter.Items[i];
             if (item.PrinterType == PrinterComboItem.Type.INITIAL_MESSAGE)
             {
                 comboPrinter.Items.RemoveAt(i);
             }
         }
     }
 }
Esempio n. 2
0
        private async void MainForm_Load(object sender, EventArgs e)
        {
            previewBox       = new PreviewBox(pictureBoxPreview);
            this.Icon        = Properties.Resources.Icon1;
            this.Text        = Properties.Resources.Title;
            labelStatus.Text = "";

            try
            {
                ManagementObjectSearcher   mos = new ManagementObjectSearcher("SELECT * FROM Win32_Printer where PrintProcessor = '" + "mariaprint" + "'");
                ManagementObjectCollection moc = mos.Get();
                foreach (ManagementObject mo in moc)
                {
                    comboPrinter.Items.Add(mo["Name"].ToString());
                }
            }
            catch
            {
                //
            }

            comboPaper.SelectedIndex = 0;

            comboColor.Items.Add("カラー");
            comboColor.Items.Add("モノクロ");
            comboColor.SelectedIndex = (int)PSFile.Color.MONO;

            comboDuplex.Items.Add("片面");
            comboDuplex.Items.Add("両面(長辺とじ)");
            comboDuplex.Items.Add("両面(短辺とじ)");
            comboDuplex.SelectedIndex = (int)PSFile.Duplex.SIMPLEX;

            if (System.Environment.GetCommandLineArgs().Count() > 1)
            {
                ps.FileName = System.Environment.GetCommandLineArgs()[1];
            }
#if DEBUG
            else
            {
                ps.FileName = "C:\\debug\\debug.ps";
                comboPrinter.Items.Add("Microsoft Print to PDF");
                comboPrinter.Items.Add("Microsoft XPS Document Writer");
                comboPrinter.Items.Add("Bad Dummy Printer");
            }
#endif
            if (comboPrinter.Items.Count > 0)
            {
                PrinterComboItem message_text = new PrinterComboItem(@"取得中...");
                message_text.PrinterType = PrinterComboItem.Type.INITIAL_MESSAGE;
                comboPrinter.Items.Add(message_text);
                comboPrinter.SelectedItem = message_text;

                if (REG.PrinterName != null)
                {
                    comboPrinter.SelectedItem = REG.PrinterName;
                }
                else
                {
                    try
                    {
                        string printer = await WebAPI.Printer();

                        if (printer != null && printer.Length > 0)
                        {
                            comboPrinter.SelectedItem = printer;
                        }
                    }
                    catch
                    {
                        // do nothing
                    }
                }

                if (comboPrinter.SelectedItem == message_text)
                {
                    comboPrinter.SelectedIndex = 0;
                }
                lock (lockObject)
                {
                    isPrinterEnabled = comboPrinter.Enabled = true;
                }
            }
        }