如何为报告查看器工具栏按钮分配快捷键?
例如,将导出的F4键指定为pdf按钮
答案 0 :(得分:2)
对于打印,我在对话框中使用了这部分代码,其中是ReportViewer控件
protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown(e);
if ((e.Key == Key.P) && (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)))
reportViewer.PrintDialog();
}
对于导出,您可以使用reportViewer.ExportDialog()
答案 1 :(得分:0)
我只是结合了几个解决方案并实现了这个解决方案
将此代码放在您的表单代码上,报告查看器就在那里。
public partial class frmReport : Form
{
public frmReportDevices()
{
InitializeComponent();
}
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == (Keys.Control | Keys.P))
{
rpt.PrintDialog();
}
if (keyData == (Keys.F2))
{
string _sSuggestedName = String.Empty;
byte[] byteViewerPDF = rpt.LocalReport.Render("PDF");
byte[] byteViewerExcel = rpt.LocalReport.Render("Excel");
byte[] byteViewerWord = rpt.LocalReport.Render("Word");
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "PDF files (.pdf)|.pdf| Doc files (.doc)|.doc| Excel files (.xls)|.xls";
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
FileStream newFile = new FileStream(saveFileDialog1.FileName, FileMode.Create);
if (saveFileDialog1.FilterIndex == 1)
{
newFile.Write(byteViewerPDF, 0, byteViewerPDF.Length);
newFile.Close();
}
else if (saveFileDialog1.FilterIndex == 2)
{
newFile.Write(byteViewerWord, 0, byteViewerWord.Length);
newFile.Close();
}
else if (saveFileDialog1.FilterIndex == 3)
{
newFile.Write(byteViewerExcel, 0, byteViewerExcel.Length);
newFile.Close();
}
}
}
return base.ProcessCmdKey(ref msg, keyData);
}
}