I would like to access the Print event of CrystalReportViewer(while I click the Print button of CrystalReportViewer) in ASP.NET C#, How ?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Something like the below should work. Hope it helps.
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");
}
回答2:
Not really a new answer but here is the above in C++ using .NET framework objects etc.:
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");
}