Click here to Skip to main content
15,908,115 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this is c# windows application about physiotherapy mgt system , i want to print bill about patient P_name,pain,no.of visit,total_charge and total_paid by particular contact no. because it's unique so, i print windows form. i did as following but, there is error in click event.

printButton.Click += new EventHandler(printButton.Click);



Error: "System.Windows.Form.Control.Click" can only appear on left hand side of += or -=

the code as follow.


crt_usr is form when i developed code.

there is some mistake and error please guide, sir, if i wrong tell me right way for print bill about define above. thank you in advance

What I have tried:

public void crt_user()
{
printButton.Text = "Print";
printButton.Click += new EventHandler(printButton.Click);
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
this.Controls.Add(printButton);
}
public void printButton_Click(object sender, EventArgs e)
{
Capturescreen();
pd.Print();
}
Bitmap memoryimage;
private void Capturescreen()
{
Graphics myGraphics = this.CreateGraphics();
Size s = this.Size;
memoryimage = new Bitmap(s.Width, s.Height, myGraphics);
Graphics memoryGraphics = Graphics.FromImage(memoryimage);
memoryGraphics.CopyFromScreen(this.Location.X, this.Location.Y, 0, 0, s);

}
private void pd_PrintPage(System.Object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawImage(memoryimage, 0, 0);
}
public static void Main()
{
Application.Run(new crt_usr());
}
Posted
Updated 17-Sep-16 23:40pm
v3

1 solution

When you copy and paste from MSDN: How to: Print a Windows Form[^] it's a good idea to make sure you don't replace "_" with "." ...

There are better ways to do this: one is to print the form directly - which isn't actually difficult, there is a class in the Visual Basic Power packs to do it for you: PrintForm Class (Microsoft.VisualBasic.PowerPacks.Printing)[^]
But a better way is to do the job properly, and use the PrintDocument Class (System.Drawing.Printing)[^] which means the user gets only the information he needs, and not the buttons and so forth as well - and any "scrolled off the page" information can be printed as well. The link includes a simple example.
 
Share this answer
 
Comments
Member 11572517 18-Sep-16 6:12am    
sir, your gave link i read that and try to make, i want to know more that how can i print bill for particular patient information, this time u show link this all said about how to print and helps, but what to print , at where i code to print what?, am i understood in way or i m confused about what u say? sorry, sir i asked many question at time. thank u.
OriginalGriff 18-Sep-16 6:29am    
Which link did you read, and how do you get the particular patient information?
Remember that we can't see your screen, access your HDD, or read your mind.
Member 11572517 18-Sep-16 6:34am    
sir, ok i read 2nd link PrintDocument Class.
OriginalGriff 18-Sep-16 6:39am    
And?
Member 11572517 18-Sep-16 6:40am    
u mean to say sir, my answer on that form and i click on print button and that execution is occured and print that information, we not to need any query or code for print like in physiotherapy mgt system i want to print bill of patient and informaion how can i do that sir? is it relevant question or i forgot something sir.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900