473,473 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Call Another Function

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.ToStr ing();
// print file
fileToPrint = new System.IO.StreamReader(appPath +
@"\Script.txt");
printFont = new System.Drawing.Font("Arial", 10);
printDocument1.Print();
fileToPrint.Close();
}
Mar 8 '07 #1
1 1383
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);
}

--
Ignacio Machin
machin AT laceupsolutions com

"Chris" <Ch***@discussions.microsoft.comwrote in message
news:20**********************************@microsof t.com...
>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.ToStr ing();
// print file
fileToPrint = new System.IO.StreamReader(appPath +
@"\Script.txt");
printFont = new System.Drawing.Font("Arial", 10);
printDocument1.Print();
fileToPrint.Close();
}

Mar 8 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: mangi03 | last post by:
Hi, I came acrosss g++ compile errors whenever I make a function call by reference and found out from the test program that compiler is treating the function argument differently when another...
3
by: JoeK | last post by:
Hey all, I am automating a web page from Visual Foxpro. I can control all the textboxes, radio buttons, and command buttons using syntax such as: ...
4
by: Dave | last post by:
I have a program that I've written a class for. I need to call the function in the program from the class. When I try to call the function I receive the error, the name xxx does not exist in the...
13
by: Bern McCarty | last post by:
I have run an experiment to try to learn some things about floating point performance in managed C++. I am using Visual Studio 2003. I was hoping to get a feel for whether or not it would make...
5
by: Kurt Van Campenhout | last post by:
Hi, I am trying to get/set Terminal server information in the active directory on a windows 2000 domain. Since the ADSI calls for TS don't work until W2K3, I need to do it myself. I'm fairly...
11
by: yangsuli | last post by:
i want to creat a link when somebody click the link the php script calls a function,then display itself :) i have tried <a href=<? funtion(); echo=$_server ?>text</a> but it will call the...
46
by: Steven T. Hatton | last post by:
I just read §2.11.3 of D&E, and I have to say, I'm quite puzzled by what it says. http://java.sun.com/docs/books/tutorial/essential/concurrency/syncrgb.html <shrug> -- NOUN:1. Money or...
0
by: Mike S | last post by:
I've seen examples of using the CallWindowProc Windows API function to call functions through their addresses in VB6 -- a clever workaround to emulate C-like function pointer semantics. A...
9
by: CryptiqueGuy | last post by:
Consider the variadic function with the following prototype: int foo(int num,...); Here 'num' specifies the number of arguments, and assume that all the arguments that should be passed to this...
6
by: RandomElle | last post by:
Hi there I'm hoping someone can help me out with the use of the Eval function. I am using Access2003 under WinXP Pro. I can successfully use the Eval function and get it to call any function with...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.