copy to clipboard | view source | convert again
Public Sub New()
InitializeComponent()
For Each ts As ToolStrip In crystalReportViewer1.Controls.OfType(Of ToolStrip)()
For Each tsb As ToolStripButton In ts.Items.OfType(Of ToolStripButton)()
'hacky but should work. you can probably figure out a better method
If tsb.ToolTipText.ToLower().Contains("print") Then
'Adding a handler for our propose
tsb.Click += New EventHandler(AddressOf printButton_Click)
End If
Next
Next
End Sub
Private Sub printButton_Click(sender As Object, e As EventArgs)
MessageBox.Show("Printed")
End Sub
ลองดูครับ
Code (C#)
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");
}
ลองแล้ว error ครับ
Public Event Click(sender As Object, e As System.EventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event