我有一個reportviewer並啓用了打印按鈕,但沒有啓用toolbar.When用戶按下輸入reportviewer應該開始printing.It應該不顯示甚至printdialog also.What代碼我應該寫在KeyPres事件?ReportViewer在C#中按下「Enter」時打印
0
A
回答
0
This是什麼爲我工作,當我想以編程方式從ReportViewer打印。
您需要將PrintController設置爲StandardPrintController以禁止打印對話框,例如
printDoc.PrintController = new System.Drawing.Printing.StandardPrintController();
0
這是我在報表查看器中進行手動打印的代碼。它在VB.NET中。 它通過處理PrintDocument對象的Print Event來工作。
Dim m_pageSettings As PageSettings 'Stores page settings for printout
Dim m_currentPage As Integer 'Used for index of pages
Private m_pages As New List(Of Stream)() 'Stores a stream for each pages
'Event fires when printDocument starts printing - reset page index to zero
Private Sub PrintDocument1_BeginPrint(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintEventArgs) Handles PrintDocument1.BeginPrint
m_currentPage = 0
End Sub
'Function that prints all the pages included in the report
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim pageToPrint As Stream = m_pages(m_currentPage)
pageToPrint.Position = 0
Dim pageMetaFile As Metafile = New Metafile(pageToPrint) 'create an image(metafile) of the report page
Using (pageMetaFile)
'Create a rectangle the size of our report - include margins
' Dim adjustedRect As Rectangle = New Rectangle(_
' e.PageBounds.Left - CType(e.PageSettings.HardMarginX, Integer), _
' e.PageBounds.Top - CType(e.PageSettings.HardMarginY, Integer), _
' e.PageBounds.Width, _
' e.PageBounds.Height)
Dim adjustedRect As Rectangle = New Rectangle(_
e.PageBounds.Left, _
e.PageBounds.Top, _
e.PageBounds.Width, _
e.PageBounds.Height)
e.Graphics.FillRectangle(Brushes.White, adjustedRect) 'Fill rectangle with WHITE background
e.Graphics.DrawImage(pageMetaFile, adjustedRect) 'Draw report in rectangle - this will be printed
m_currentPage = m_currentPage + 1
e.HasMorePages = m_currentPage < m_pages.Count 'If more pages are left - keep processing
End Using
End Sub
'Event fires when PrintDocument queries for PageSettings. Return a copy of m_pagesettings.
Private Sub PrintDocument1_QueryPageSettings(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.QueryPageSettingsEventArgs) Handles PrintDocument1.QueryPageSettings
e.PageSettings = CType(m_pageSettings.Clone, PageSettings)
End Sub
'Render the report in a EMF - This function creates metafiles(images) of each page in the report
Private Sub RenderAllLocalReportPages(ByVal localReport As LocalReport)
Dim deviceInfo As String = CreateEMFDeviceInfo() 'Enhanced MetaFile
Dim warnings As Warning() = Nothing
localReport.Render("IMAGE", deviceInfo, AddressOf LocalReportCreateStreamCallback, warnings)
End Sub
'Callback function used with RenderAllLocalReportPages
Private Function LocalReportCreateStreamCallback(ByVal name As String, ByVal extension As String, ByVal encoding As Encoding, ByVal mimeType As String, ByVal willSeek As Boolean) As Stream
Dim stream As New MemoryStream()
m_pages.Add(stream)
Return stream
End Function
Private Function CreateEMFDeviceInfo() As String
Dim paperSize As PaperSize = m_pageSettings.PaperSize
Dim margins As Margins = m_pageSettings.Margins
'The device info string defines the page range to print as well as the size of the page.
'A start and end page of 0 means generate all pages.
Return String.Format(CultureInfo.InvariantCulture, "<DeviceInfo><OutputFormat>emf</OutputFormat><StartPage>0</StartPage><EndPage>0</EndPage><MarginTop>{0}</MarginTop><MarginLeft>{1}</MarginLeft><MarginRight>{2}</MarginRight><MarginBottom>{3}</MarginBottom><PageHeight>{4}</PageHeight><PageWidth>{5}</PageWidth></DeviceInfo>", ToInches(margins.Top), ToInches(margins.Left), ToInches(margins.Right), ToInches(margins.Bottom), ToInches(paperSize.Height), ToInches(paperSize.Width))
End Function
'Convert report printing size to inches
Private Shared Function ToInches(ByVal hundrethsOfInch As Integer) As String
Dim inches As Double = hundrethsOfInch/100.0R
Return inches.ToString(CultureInfo.InvariantCulture) & "in"
End Function
0
我正在爲我的項目使用自定義報告。自定義是指使用e.Graphics.DrawString類型代碼構建的報表。
所以我在PrintDocument
默認打印事件所做的所有的報告(編碼),這裏是PrintDocument關聯的工具。將它拖放到屏幕上,然後雙擊它以創建事件處理程序。
的PrintDocoument
事件處理程序背後的代碼是:
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
Image image = Properties.Resources.New_Header;
Font font = new Font("Arial", 7, FontStyle.Bold);
Font font2 = new Font("Arial", 7, FontStyle.Regular);
float fontHeight = font2.GetHeight();
e.Graphics.DrawImage(image, 20, 5, 260, 130);
e.Graphics.DrawString("Date:" + DateTime.Now.ToShortDateString(), new Font("Arial", 7, FontStyle.Bold), Brushes.Black, new Point(20, 160));
e.Graphics.DrawString("Invoice#: "+InvoiceNoTextBox.Text, new Font("Arial", 7, FontStyle.Bold), Brushes.Black, new Point(160, 160));
e.Graphics.DrawString("Client Name: " + ClientNameTextBox.Text.Trim(), new Font("Arial", 7, FontStyle.Bold), Brushes.Black, new Point(20, 180));
e.Graphics.DrawString("______________________________",
new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(20, 190));
e.Graphics.DrawString("Product", new Font("Arial", 7, FontStyle.Bold), Brushes.Black, new Point(23, 220));
e.Graphics.DrawString("U/Price", new Font("Arial", 7, FontStyle.Bold), Brushes.Black, new Point(170, 220));
e.Graphics.DrawString("Qty", new Font("Arial", 7, FontStyle.Bold), Brushes.Black, new Point(210, 220));
e.Graphics.DrawString("Total", new Font("Arial", 7, FontStyle.Bold), Brushes.Black, new Point(240, 220));
e.Graphics.DrawString("______________________________",
new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(20, 220));
int CurrentX = 25;
int CurrentY = 230;
int offset = 20;
foreach (var i in shoppingCart)
{
e.Graphics.DrawString(i.ItemName, new Font("Arial", 7, FontStyle.Regular), Brushes.Black, new Point(CurrentX, CurrentY+offset));
e.Graphics.DrawString(i.UnitPrice.ToString(), new Font("Arial", 7, FontStyle.Regular), Brushes.Black, new Point(180, CurrentY + offset));
e.Graphics.DrawString(i.Quantity.ToString(), new Font("Arial", 7, FontStyle.Regular), Brushes.Black, new Point(215, CurrentY + offset));
e.Graphics.DrawString(i.TotalPrice.ToString(), new Font("Arial", 7, FontStyle.Regular), Brushes.Black, new Point(240, CurrentY + offset));
offset = offset + (int)fontHeight + 5;
}
CurrentY = CurrentY+offset;
e.Graphics.DrawString("______________________________",
new Font("Arial", 12, FontStyle.Regular), Brushes.Black, new Point(20, CurrentY-5));
e.Graphics.DrawString("Total Amt: Rs." + TotalAmountTextBox.Text, new Font("Arial", 7, FontStyle.Regular), Brushes.Black, new Point(180, CurrentY + 35));
e.Graphics.DrawString("Discount%: " + DiscountTextBox.Text.Trim()+"%", new Font("Arial", 7, FontStyle.Regular), Brushes.Black, new Point(180, CurrentY + 50));
e.Graphics.DrawString("Discount: Rs." + JustDiscountTextBox.Text.Trim(), new Font("Arial", 7, FontStyle.Regular), Brushes.Black, new Point(180, CurrentY + 65));
e.Graphics.DrawString("Grand Total: Rs." + TotalToPayTextBox.Text, new Font("Arial", 7, FontStyle.Regular), Brushes.Black, new Point(180, CurrentY + 80));
e.Graphics.DrawString("Advance: Rs." + AdvancePaymentTextBox.Text.Trim(), new Font("Arial", 7, FontStyle.Regular), Brushes.Black, new Point(20, CurrentY + 95));
e.Graphics.DrawString("Cash: Rs." + givenCash.Text.Trim(), new Font("Arial", 7, FontStyle.Regular), Brushes.Black, new Point(180, CurrentY + 95));
e.Graphics.DrawString("Pending: Rs." + PendingPaymentTextBox.Text, new Font("Arial", 7, FontStyle.Regular), Brushes.Black, new Point(20, CurrentY + 110));
e.Graphics.DrawString("Return: Rs." + ReturnTextBox.Text, new Font("Arial", 7, FontStyle.Regular), Brushes.Black, new Point(180, CurrentY + 110));
e.Graphics.DrawString("Software Provided By Muhammad Abbas", new Font("Arial", 7, FontStyle.Regular), Brushes.Black, new Point(20, CurrentY + 125));
e.Graphics.DrawString("Mob:0304-9550308", new Font("Arial", 7, FontStyle.Regular), Brushes.Black, new Point(20, CurrentY + 140));
}
private void PrintPreviewButton_Click(object sender, EventArgs e)
{
try
{
printPreviewDialog1.Document = printDocument1;
printPreviewDialog1.ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
終於解答你的問題。在你的表格KeyDown
事件中使用這個。
private void Form_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
printDocument1.Print();
}
}
它會直接從您的打印機打印您的收據。
相關問題
- 1. 打印按鈕在ReportViewer中不可見
- 2. 的ReportViewer打印按鈕
- 3. 按Enter鍵跳過打印?
- 4. 當我按下C#窗口中的按鈕時,如何在沒有reportviewer的情況下打印RDLC報告?
- 5. 在ReportViewer C中更改打印按鈕的行爲#
- 6. 按下「Enter」鍵將值打印到控制檯日誌中
- 7. ReportViewer打印問題
- 8. C#:按下Enter鍵時更改DropDownList值
- 9. C#按Enter鍵按下按鈕
- 10. 當按下Enter鍵時
- 11. 在使用IE11的ReportViewer中不能使用打印按鈕
- 12. 分頁符打印ReportViewer時打印多頁?
- 13. 按鍵時按下打印文字
- 14. 打印ReportViewer沒有預覽
- 15. 僅在按下ENTER時提交。
- 16. 沒有的ReportViewer打印報表在ASP.NET
- 17. 打印不起作用在ReportViewer
- 18. 在打印預覽模式下獲取ReportViewer的當前頁面?
- 19. 如何在沒有預覽的情況下打印Reportviewer
- 20. ReportViewer在打印佈局模式下顯示黑色背景
- 21. 打印,同時按下鼠標
- 22. Java:按下0時平均打印
- 23. C++檢測用戶按下的ENTER鍵
- 24. 打印圖像在GridView中打印按鈕c#asp.net
- 25. 在按下WPF DataGrid中的Enter鍵時移至下一列
- 26. 使用C#窗口中的ReportViewer打印PDF
- 27. 按Enter繼續在C
- 28. 如何在C#中打印垂直文本? (StringFormat.DirectionVirtical打印下來)
- 29. 阻止<a>按下ENTER鍵時打開鏈接
- 30. KendoUI Grid按下Enter鍵時保存
oki ...我會檢查...謝謝 – 2009-07-27 04:07:12