2011-02-14 5 views
1

보고서 뷰어 도구 모음 단추에 바로 가기 키를 할당하는 방법은 무엇입니까? 난 당신이 아마 reportViewer.ExportDialog을 사용할 수 있습니다 수출의 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(); 
} 

에게 있습니다 대화 상자에서 코드의이 부분을 사용하여 인쇄를 들어

답변

2

PDF 버튼으로 수출 F4 키를 할당 예를 들어

()

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); 
     } 
} 
관련 문제