我想在ASP.NET C#中访问CrystalReportViewer的Print事件(当我点击CrystalReportViewer的Print按钮时),怎么做?
答案 0 :(得分:7)
下面的内容应该有效。希望它有所帮助。
public Form1()
{
InitializeComponent();
foreach (ToolStrip ts in crystalReportViewer1.Controls.OfType<ToolStrip>())
{
foreach (ToolStripButton tsb in ts.Items.OfType<ToolStripButton>())
{
//hacky but should work. you can probably figure out a better method
if (tsb.ToolTipText.ToLower().Contains("print"))
{
//Adding a handler for our propose
tsb.Click += new EventHandler(printButton_Click);
}
}
}
}
private void printButton_Click(object sender, EventArgs e)
{
MessageBox.Show("Printed");
}
答案 1 :(得分:0)
不是一个新的答案,但这里是上面的C ++使用.NET框架对象等:
CRXViewerNetControl(void)
{
InitializeComponent();
// OK, go though the CRViewer and find the Print Button in the toolbar. When we find it,
// attach a "Click" event handler so that we can detect the operator clicking the button to
// print the report.
for (Int32 i = 0; i < CRXViewer->Controls->Count; i++)
{
if (dynamic_cast<System::Windows::Forms::ToolStrip^>(CRXViewer->Controls[i]))
{
System::Windows::Forms::ToolStrip^ ctlToolStrip = dynamic_cast<System::Windows::Forms::ToolStrip^>(CRXViewer->Controls[i]);
for (int j = 0; j < ctlToolStrip->Items->Count; j++)
{
if (dynamic_cast<System::Windows::Forms::ToolStripButton^>(ctlToolStrip->Items[j]))
{
System::Windows::Forms::ToolStripButton^ ctlToolStripButton = dynamic_cast<System::Windows::Forms::ToolStripButton^>(ctlToolStrip->Items[j]);
if (ctlToolStripButton->ToolTipText->ToLower()->Contains("print"))
{
//Adding a handler for our propose
ctlToolStripButton->Click += gcnew System::EventHandler(this, &CRXViewerNetControl::printButton_Click);
}
}
}
}
}
}
private: System::Void printButton_Click(System::Object^ sender, System::EventArgs^ e)
{
MessageBox::Show("Printed");
}