public void Print_ShouldNotPrintIfPrintDialogResultIsNotOK() { _printDialogFacade.ShowDialog().Returns(DialogResult.Abort); _printer.Print(); _printDocumentFacade.DidNotReceive().Print(); _printDialogFacade.ShowDialog().Returns(DialogResult.Cancel); _printer.Print(); _printDocumentFacade.DidNotReceive().Print(); _printDialogFacade.ShowDialog().Returns(DialogResult.Ignore); _printer.Print(); _printDocumentFacade.DidNotReceive().Print(); _printDialogFacade.ShowDialog().Returns(DialogResult.No); _printer.Print(); _printDocumentFacade.DidNotReceive().Print(); _printDialogFacade.ShowDialog().Returns(DialogResult.None); _printer.Print(); _printDocumentFacade.DidNotReceive().Print(); _printDialogFacade.ShowDialog().Returns(DialogResult.Retry); _printer.Print(); _printDocumentFacade.DidNotReceive().Print(); _printDialogFacade.ShowDialog().Returns(DialogResult.Yes); _printer.Print(); _printDocumentFacade.DidNotReceive().Print(); }
private Image GetRtfImage(int rowIndex, object value, bool selected) { Size cellSize = GetSize(rowIndex); if (cellSize.Width < 1 || cellSize.Height < 1) { return(null); } RichTextBox ctl = null; if (ctl == null) { //ctl = _editingControl; ctl = new RichTextBox(); ctl.Size = GetSize(rowIndex); SetRichTextBoxText(ctl, Convert.ToString(value)); } if (ctl != null) { // Print the content of RichTextBox to an image. Size imgSize = new Size(cellSize.Width - 1, cellSize.Height - 1); Image rtfImg = null; if (selected) { // Selected cell state ctl.BackColor = DataGridView.DefaultCellStyle.SelectionBackColor; ctl.ForeColor = DataGridView.DefaultCellStyle.SelectionForeColor; // Print image rtfImg = RichTextBoxPrinter.Print(ctl, imgSize.Width, imgSize.Height); // Restore RichTextBox ctl.BackColor = DataGridView.DefaultCellStyle.BackColor; ctl.ForeColor = DataGridView.DefaultCellStyle.ForeColor; } else { //add by 20131219 start コントロールの背景色がグリッド行に合せるため ctl.BackColor = DataGridView.Rows[this.RowIndex].DefaultCellStyle.BackColor; ctl.ForeColor = DataGridView.Rows[this.RowIndex].DefaultCellStyle.ForeColor; //add by 20131219 end rtfImg = RichTextBoxPrinter.Print(ctl, imgSize.Width, imgSize.Height); //add by 20131219 start コントロールの背景色がグリッド行に合せるため // Restore RichTextBox ctl.BackColor = DataGridView.Rows[this.RowIndex].DefaultCellStyle.BackColor; ctl.ForeColor = DataGridView.Rows[this.RowIndex].DefaultCellStyle.ForeColor; //add by 20131219 end } return(rtfImg); } return(null); }
private void PrintDocumentPrintPage(object sender, PrintPageEventArgs e) { try { e.HasMorePages = RichTextBoxPrinter.Print(richTextBox, ref _charFrom, e); } catch (Exception ex) { MessageBox.Show(ex.Message, Resources.MainForm_PrintDocumentPrintPage_Print_error, MessageBoxButtons.OK, MessageBoxIcon.Error); e.Cancel = true; } }
// Images for selected and normal states. private Image GetRtfImage(int rowIndex, object value, bool selected, DataGridViewCellStyle cellStyle, int?leftAlignment) { Size cellSize = GetSize(rowIndex); if (cellSize.Width < 1 || cellSize.Height < 1) { return(null); } //RichTextBox ctl = _editingControl; DataGridViewTrackEditingControl ctl = _editingControl; if (ctl == null) { return(null); } //ctl.ApplyCellStyleToEditingControl(cellStyle); ctl.Size = GetSize(rowIndex); ctl.Font = cellStyle.Font; ctl.ParityText = (StringWithParity)value; //ctl.Text = ((CRCString)value).ToString(); if (leftAlignment == null) { switch (cellStyle.Alignment) { case DataGridViewContentAlignment.MiddleLeft: ctl.SelectionAlignment = HorizontalAlignment.Left; break; case DataGridViewContentAlignment.MiddleRight: ctl.SelectionAlignment = HorizontalAlignment.Right; break; default: ctl.SelectionAlignment = HorizontalAlignment.Center; break; } leftAlignment = 0; } // Print the content of RichTextBox to an image. Size imgSize = new Size(cellSize.Width - _editingControl.Margin.Left - _editingControl.Margin.Right + 1 - leftAlignment.Value * fontSize.Width, cellSize.Height - _editingControl.Margin.Bottom - _editingControl.Margin.Top + 1); //it might happen if alignment is big. if (imgSize.Width <= 0) { imgSize.Width = 1; } Image rtfImg = null; if (selected) { // Selected cell state ctl.BackColor = DataGridView.DefaultCellStyle.SelectionBackColor; ctl.ForeColor = DataGridView.DefaultCellStyle.SelectionForeColor; // Print image rtfImg = RichTextBoxPrinter.Print(ctl, imgSize.Width, imgSize.Height); // Restore RichTextBox ctl.BackColor = DataGridView.DefaultCellStyle.BackColor; ctl.ForeColor = DataGridView.DefaultCellStyle.ForeColor; } else { rtfImg = RichTextBoxPrinter.Print(ctl, imgSize.Width, imgSize.Height); } return(rtfImg); }