Call Another Function

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have this code below for printing a report. How can I execute (cal) this
code from a menu button too?

// this is a routine for printing out the script.txt file
System.IO.StreamReader fileToPrint;
System.Drawing.Font printFont;
private void buttonLoad_Click(System.Object sender, System.EventArgs
e)
{
//get application path
string appPath;
appPath = System.Windows.Forms.Application.StartupPath.ToString();
// print file
fileToPrint = new System.IO.StreamReader(appPath +
@"\Script.txt");
printFont = new System.Drawing.Font("Arial", 10);
printDocument1.Print();
fileToPrint.Close();
}
 
Hi,

Either you assign the same method to the onClick of your button

myButton.Click += new EventHandler( buttonLoad_Click);

or just call it from the event handler of the control:

myButton.Click += new EventHandler( myButton_Click);

private void myButton_Click(System.Object sender, System.EventArgs
e)
{
buttonLoad( sender, e);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top