コード例 #1
0
        private void MainWindow_Load(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            // Load settings
            Debug.WriteLine("First reference to ModelLocator.Current.Settings");
            var sheets = ModelLocator.Current.Settings.Sheets;

            ModelLocator.Current.Settings.PropertyChanged += (s, e) => BeginInvoke((Action)(() => {
                Debug.WriteLine($"Settings.PropertyChanged: {e.PropertyName}");
                switch (e.PropertyName)
                {
                case "DefaultSheet":
                    comboBoxSheet.Text = ModelLocator.Current.Settings.Sheets.GetValueOrDefault(ModelLocator.Current.Settings.DefaultSheet.ToString()).Name;
                    ChangeSheet();
                    break;
                }
            }));

            comboBoxSheet.DisplayMember = "Value";
            comboBoxSheet.ValueMember   = "Key";
            foreach (var s in sheets)
            {
                comboBoxSheet.Items.Add(new KeyValuePair <string, string>(s.Key, s.Value.Name));
            }

            // Select default printer and paper size
            foreach (string printer in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
            {
                printersCB.Items.Add(printer);
                //printersCB.Text = "OneNote";
                if (printDoc.PrinterSettings.IsDefaultPrinter)
                {
                    printersCB.Text = printDoc.PrinterSettings.PrinterName;
                }
            }
            printDoc.PrinterSettings.PrinterName = (string)printersCB.SelectedItem;
            foreach (PaperSize ps in printDoc.PrinterSettings.PaperSizes)
            {
                paperSizesCB.Items.Add(ps);
            }
            paperSizesCB.Text = printDoc.DefaultPageSettings.PaperSize.ToString();

            // We kept these disabled during load
            printersCB.Enabled   = true;
            paperSizesCB.Enabled = true;

            // Select default Sheet
            comboBoxSheet.Text = ModelLocator.Current.Settings.Sheets.GetValueOrDefault(ModelLocator.Current.Settings.DefaultSheet.ToString()).Name;

            if (ModelLocator.Current.Options.Files != null)
            //&&
            //  ModelLocator.Current.Options.Files.Any() &&
            //  !string.IsNullOrEmpty(ModelLocator.Current.Options.Files.ToList<string>()[0]))
            {
                file = ModelLocator.Current.Options.Files.ToList()[0];
            }

            printPreview.Select();
            this.Size        = new Size(ModelLocator.Current.Settings.Size.Width, ModelLocator.Current.Settings.Size.Height);
            this.Location    = new Point(ModelLocator.Current.Settings.Location.X, ModelLocator.Current.Settings.Location.Y);
            this.WindowState = (System.Windows.Forms.FormWindowState)ModelLocator.Current.Settings.WindowState;

            this.Cursor = Cursors.Default;

            if (string.IsNullOrEmpty(file))
            {
                using (OpenFileDialog openFileDialog = new OpenFileDialog()) {
                    openFileDialog.InitialDirectory = $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}\\source\\winprint\\tests";
                    openFileDialog.Filter           = "code files (*.c*)|*.c*|txt files (*.txt)|*.txt|All files (*.*)|*.*";
                    openFileDialog.FilterIndex      = 3;
                    openFileDialog.RestoreDirectory = true;
                    if (openFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        file = openFileDialog.FileNames.ToList <string>()[0];
                    }
                }
            }
            // Go!
            ChangeSheet();
        }
コード例 #2
0
        private void PropertyChangedEventHandler(object o, PropertyChangedEventArgs e)
        {
            if (InvokeRequired)
            {
                BeginInvoke((Action)(() => PropertyChangedEventHandler(o, e)));
            }
            else
            {
                Core.Helpers.Logging.TraceMessage($"SheetViewModel.PropertyChanged: {e.PropertyName}");
                switch (e.PropertyName)
                {
                case "Landscape":
                    Core.Helpers.Logging.TraceMessage($"  Checking checkbox: {ModelLocator.Current.Settings.Sheets.GetValueOrDefault(ModelLocator.Current.Settings.DefaultSheet.ToString()).Landscape}");
                    landscapeCheckbox.Checked = printPreview.SheetViewModel.Landscape;
                    break;

                case "Header":
                    headerTextBox.Text = printPreview.SheetViewModel.Header.Text;
                    break;

                case "Footer":
                    footerTextBox.Text = printPreview.SheetViewModel.Footer.Text;
                    break;

                case "Margins":
                    topMargin.Value    = printPreview.SheetViewModel.Margins.Top / 100M;
                    leftMargin.Value   = printPreview.SheetViewModel.Margins.Left / 100M;
                    rightMargin.Value  = printPreview.SheetViewModel.Margins.Right / 100M;
                    bottomMargin.Value = printPreview.SheetViewModel.Margins.Bottom / 100M;

                    // Keep PrintDocument updated for WinForms.PrintPreview
                    printDoc.PrinterSettings.DefaultPageSettings.Margins = (Margins)printPreview.SheetViewModel.Margins.Clone();
                    break;

                case "PageSeparator":
                    pageSeparator.Checked = printPreview.SheetViewModel.PageSeparator;
                    break;

                case "Rows":
                    rows.Value = printPreview.SheetViewModel.Rows;
                    break;

                case "Columns":
                    columns.Value = printPreview.SheetViewModel.Columns;
                    break;

                case "Padding":
                    padding.Value = printPreview.SheetViewModel.Padding / 100M;
                    break;

                case "File":
                    this.Text = $"WinPrint - {printPreview.SheetViewModel.File}";
                    printPreview.CurrentSheet = 1;
                    break;

                case "Content":
                    printPreview.CurrentSheet = 1;
                    SheetSettingsChanged();
                    break;

                case "Loading":
                    printPreview.Text = printPreview.SheetViewModel.Loading ? "Loading..." : "";
                    printPreview.Invalidate(false);
                    printPreview.Select();
                    printPreview.Focus();
                    break;

                case "Reflowing":
                    printPreview.Text = printPreview.SheetViewModel.Reflowing ? "Rendering..." : "";
                    printPreview.Invalidate(false);
                    break;
                }
            }
        }