コード例 #1
0
        public MainWindow()
        {
            InitializeComponent();

            Icon = Resources.printer_and_fax_w;

            printPreview             = new PrintPreview();
            printPreview.Dock        = this.dummyButton.Dock;
            printPreview.Anchor      = this.dummyButton.Anchor;
            printPreview.BackColor   = this.dummyButton.BackColor;
            printPreview.Location    = this.dummyButton.Location;
            printPreview.Margin      = this.dummyButton.Margin;
            printPreview.Name        = "printPreview";
            printPreview.Size        = this.dummyButton.Size;
            printPreview.MinimumSize = new Size(0, 0);
            printPreview.TabIndex    = 1;
            printPreview.TabStop     = true;

            printPreview.KeyUp += (s, e) => {
                switch (e.KeyCode)
                {
                case Keys.F5:
                    printPreview.Invalidate(true);
                    Core.Helpers.Logging.TraceMessage("-------- F5 ---------");
                    Task.Run(() =>
                             printPreview.SheetViewModel.LoadAsync(printPreview.SheetViewModel.File).ConfigureAwait(false));
                    break;
                }
            };


            if (LicenseManager.UsageMode != LicenseUsageMode.Designtime)
            {
                this.panelRight.Controls.Remove(this.dummyButton);
                this.panelRight.Controls.Add(this.printPreview);
                printersCB.Enabled   = false;
                paperSizesCB.Enabled = false;
            }
        }
コード例 #2
0
        private SheetViewModel CreatePreviewSheetViewModel()
        {
            Debug.WriteLine("CreateSheetViewModel");
            SheetViewModel svm = new SheetViewModel();

            svm.SetSettings(ModelLocator.Current.Settings.Sheets.GetValueOrDefault(ModelLocator.Current.Settings.DefaultSheet.ToString()));

            landscapeCheckbox.Checked = svm.Landscape;
            enableHeader.Checked      = svm.Header.Enabled;
            headerTextBox.Text        = svm.Header.Text;
            enableFooter.Checked      = svm.Footer.Enabled;
            footerTextBox.Text        = svm.Footer.Text;

            topMargin.Value    = svm.Margins.Top / 100M;
            leftMargin.Value   = svm.Margins.Left / 100M;
            rightMargin.Value  = svm.Margins.Right / 100M;
            bottomMargin.Value = svm.Margins.Bottom / 100M;

            pageSeparator.Checked = svm.PageSepartor;
            rows.Value            = svm.Rows;
            columns.Value         = svm.Columns;
            padding.Value         = svm.Padding / 100M;

            svm.PropertyChanged += (s, e) => BeginInvoke((Action)(() => {
                Debug.WriteLine($"SheetViewModel.PropertyChanged: {e.PropertyName}");
                switch (e.PropertyName)
                {
                case "Landscape":
                    Debug.WriteLine($"  Checking checkbox: {ModelLocator.Current.Settings.Sheets.GetValueOrDefault(ModelLocator.Current.Settings.DefaultSheet.ToString()).Landscape}");
                    landscapeCheckbox.Checked = svm.Landscape;
                    break;

                case "Header":
                    headerTextBox.Text = svm.Header.Text;
                    break;

                case "Footer":
                    footerTextBox.Text = svm.Footer.Text;
                    break;

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

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

                case "PageSeparator":
                    pageSeparator.Checked = svm.PageSepartor;
                    break;

                case "Rows":
                    rows.Value = svm.Rows;
                    break;

                case "Columns":
                    columns.Value = svm.Columns;
                    break;

                case "Padding":
                    padding.Value = svm.Padding / 100M;
                    break;
                }
            }));

            svm.SettingsChanged += (s, reflow) => BeginInvoke((Action)(() => {
                Debug.WriteLine($"SheetViewModel.SettingsChanged: {reflow}");
                if (reflow)
                {
                    SheetSettingsChanged();
                }
                else
                {
                    printPreview.Invalidate(false);
                }
            }));

            printPreview.SheetViewModel = svm;

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

            svm.File  = file;
            this.Text = $"WinPrint - {file}";
            return(svm);
        }
コード例 #3
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;
                }
            }
        }