Hi friends, here i am going to make an Application "how can take Print Receipt and save data in database in windows Forms application".This project is very helpful for your Real Time Project Development and you can achieve more knowledge from this projects. You can download whole Application from the bottom of this page.
Step7:- Create Studentdetail1 table in SQL Database for save the Form1 data on click on Submit Button.
see it:
Step9:- Now go Form2.cs(Design) File-> Double click on Preview button-> write the following code which are given below:-
Step11: Now you can see the studentdetail1 table data after the printout of the form.
see it:-
Download whole Attached application
DOWNLOAD
There are some steps ,Please follow it
Step1:- Open your visual studio-> File->Click New Project->Select Windows Forms Application -> Select c# language from left window->write your application name->click OK.
Step2:- Now open Form1.cs(Design) File->Drag and drop label ,Text Box and Button Control from Toolbox-> change the label name as shown below
Step3:- Add New Form form solution Explorer windows->go Form2.cs(Design) File->Drag and drop TableLayoutPanel From Toolbox-> go Property of TableLayoutPanel and change the RowCount =7.
SEE IT:->
Step4:- Drag and drop label control from Toolbox-> change the Label Name as below: see it:-
Step5:- Now go Property o each label (9,10,11,12,13,14,15) and change Each label Modifiers=Public
SEE IT:-
Step6:- Now drag and drop printDocument1 and printPreviewDialog1 control from the Toolbox on the Form 2-> go property of printPreviewDialog1 and select Document = printDocument1.
see it:-
Step7:- Create Studentdetail1 table in SQL Database for save the Form1 data on click on Submit Button.
see it:
Step8:- Now go Form 1->Double click on Submit Button -> Write the following codes which are given below:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace print_recipt
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
SqlDataAdapter da;
DataSet ds;
SqlConnection con;
private void button1_Click(object sender, EventArgs e)
{
con = new SqlConnection("data source=RAMASHANKER-PC;Integrated Security=Yes;Database=master");
da = new SqlDataAdapter("insert into studentdetail1 values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + textBox6.Text + "')", con);
ds = new DataSet();
da.Fill(ds);
//MessageBox.Show("Fee has been successfully Submitted");
Form2 f2 = new Form2();
this.Hide();
f2.label9.Text = textBox1.Text.ToString();
f2.label10.Text = textBox2.Text.ToString();
f2.label11.Text = textBox3.Text.ToString();
f2.label12.Text = textBox4.Text.ToString();
f2.label13.Text = textBox5.Text.ToString();
f2.label14.Text = textBox6.Text.ToString();
int n1 = int.Parse(textBox5.Text);
int n2 = int.Parse(textBox6.Text);
int total = n1 + n2;
f2.label15.Text = total.ToString();
f2.Show();
}
}
}
- Write the above code on the Form1.cs File.
Step9:- Now go Form2.cs(Design) File-> Double click on Preview button-> write the following code which are given below:-
using System;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Printing;
namespace print_recipt
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
[System.Runtime.InteropServices.DllImport("gdi32.dll")]
public static extern long BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
private 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);
IntPtr dc1 = mygraphics.GetHdc();
IntPtr dc2 = memoryGraphics.GetHdc();
BitBlt(dc2, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height, dc1, 0, 0, 13369376);
mygraphics.ReleaseHdc(dc1);
memoryGraphics.ReleaseHdc(dc2);
}
private void button1_Click(object sender, EventArgs e)
{
CaptureScreen();
printPreviewDialog1.ShowDialog();
}
private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
{
e.Graphics.DrawImage(memoryImage, 0, 0);
}
}
}
- Write the above code on the Form2.cs File.
Step10:-
- Now Run The Application(Press F5)-> Fill the data on the Form1.cs(Design) File.
- Click the Submit button-> then you will go to the Form 2.
see it:
- Now click the Preview button -> Take printout on click on print button.
see it:-
see it:-
For more:
- Add sql Database(.mdf) in Asp.Net ApplicationPrint the Grid Data in Windows FormsApplication
- Create .dll File and Use in Asp.netApplication
- Create a Setup File
- File Handling Real Application
- Ado.Net Application
- Make Captcha image for Asp.NetApplication
- E-Post System Project
- How to use application state and global.asax file in asp.net
- How to use binding Navigator controls in asp.net
- Web Form controls in asp.net
- How to solve sql server database (.mdf) file problems
- How to make custom login and Registration page
- Call by value and call by reference in c#
- Data set and Data adopter in c#
Download whole Attached application
DOWNLOAD
[System.Runtime.InteropServices.DllImport("gdi32.dll")] in this error occur
ReplyDelete@Sunny Dhiman ,there are some missing .dll file in your visual studio.follow the below steps
ReplyDeleteopen your solution Explorer -->right click on project--->Add Reference--> .NET--> select all InteropServices one by one-->ok .then you can run this application without error.
I need to do a textile billing application.. how can i use the printing . here it takes the screen shot fully.. i need just the contents.. what to do?
ReplyDeleteyou can use session variable to transfer value from one page to another page and use java script code for printing.
DeleteHow could i do this website?
ReplyDeletefirst use session variable for transfer the control value to another page and use java script or j query for printing this page.
DeleteHii i have an application where there are lots of lables and textboxes here i want to print the text of lables and text inside the textbox and i did it but only printing the content which is fitting in one page in preview im unable to extend the content to print to next page ...so how can I do it Please help me
ReplyDeleteHi Muzammil tell me,which type of application you are using windows Forms or asp.net.you can send snapshot of your page on my Email-ramashanker@outlook.com .then i can help you.
Deletethanks it s really nice. i have one doubt from datagridview. i save student details name,id,phone. and show in gridview . then i doubleclick the any row in gridview another form need to open and get value form datagrid selected value and display on name field name, id field id, and so on. guide me my mail id manojija007@gmail.com
ReplyDeleteMine data is not shown in the print page..data is being inserted but not shown when i click on the preview button,its shows me blank page to print
ReplyDelete@Ravinder singh saini, follow step 5 carefully .it will work definetly......
DeleteI have followed it sir,i used try-catch now it gives invalid printer exception.
ReplyDeletehey sir when i click on print button it doesn't show any preview...
ReplyDeletehi suraj,go properties of each control on form2,change Modifier==public,see step 5 ,i have already mentioned it.
ReplyDeleteDEAR SIR THIS CODE ONLY USE IN WEB FORM , THAN HOW USE THIS CODE FOR WEB APPLICATION DATA ENTRY IN C#
ReplyDeleteBECAUSE MY DATA ENTRY FORM IN WEB APPLICATION
PLEASE GUIDE ME
hi sandesh, you can use same concepts in web application also but you need to write same code as web application using c#.i have already posted many post please read it and implement in your projects.
DeleteThank you so much for your post because this is very useful for me at the end time of my project...
ReplyDeletetc...gn
sir i need ado.net material will plzz forward to this mail id.
ReplyDeleteraja.sekhar0011@gmail.com
I am going to write a code for print page and receipts in asp.net,c#. whenever we works on any website and software – we need to print some report and date using printer. So now we are going to learn write thing on write place.
ReplyDeleteSo for this execution we need to follow some step. You can also find here attached application here Print demo application
Firstly we creates a new website and a newpage and create new app_code folder .
Here we writes a code for print in app_code folder that is work as class file.
Add a class file in app_code folder with te name of PrintHelper.cs.
Code for PrintHelper.cs in App_code : -
http://nirajtiwari.com/code-print-receiptpage-asp-net-c/
hi sir,
ReplyDeletethank u for sending me the material. And one more request will please guide how can i prepare the ado.net and get succeed in get the job please give some guide lines.....
hi sekhar ! only focus on your concepts.If you know concepts very well ,I hope ,you will get job definitely.There are some points which you have to follow.
ReplyDelete1.) English communication
2.) Technical Knowledge(aptitude,reasoning)
3.) Language knowledge(c or c++ or c# or java)
Attention :-Now days English communication is more important......
you can learn aptitude,reasoning and other technical things from below url.
http://www.indiabix.com/
if any query ask again.....
i sir may i knw where r u from and will please give me ur phne no to contact if u dnt mine i wan clarify my douts through call.
ReplyDeleteits also showing button on print
ReplyDeletehiiiiiiii,Actually i have done integration part of camera in c# windows application through metricam. now i want code for capturing image and that images is save in Database.Please Help me. send me that code on my email id
ReplyDeletevaibhavb029@gmail.com
Refer below link it may be helpful for you...
Deletehttp://www.codeproject.com/Articles/125478/Versatile-WebCam-C-library
error from sql server
ReplyDeletehi Krishnan ! it may be version problem,so you have to create your own sql database on your system .
Deletehello sir i have tried ur code but i am getting print of half windows form nly plzzz help?
ReplyDeletehi alex ! Follow step 5 carefully.you can print only visible screen on your desktoponly in windows form application.
Deletehello mr.ramashanker i put your code in my form which has textbox so its not working why??? ...
ReplyDeletehello mr.ramashankar .. i want to print form which has textbox and picturebox with image but this code not working ... how to print colorful form with images form
ReplyDeletehi priyank ! follow step 5 ,6 carefully,set all control's modifier = public,.Then you can print whole form without any problem,For color print, you have to use color printer...
Deletethis doesn't work, errer "document does not contain any pages", i think the Form2 you post lost a little code. :|
ReplyDeletebhaii apni chaii ki dukaan hai , ye sofware bnaya , but wo peela wala form kaise bnauu, koi btaega to usko free chaii pilaunga
ReplyDeletein place of sql server db want to use ms excel, can you help to get the method
ReplyDeleteHi,
ReplyDeleteFor me data is not shown in the print page..data is getting inserted in database also but not shown when i click on the preview button,its shows me blank page to print
and I am getting these errors
Could not copy "obj\x86\Debug\PrintReceipt1.exe" to "bin\Debug\PrintReceipt1.exe".Exceeded retry count of 10.Failed.
Unable to copy file "obj\x86\Debug\PrintReceipt1.exe" to "bin\Debug\PrintReceipt1.exe".The process can not access the file "bin\Debug\PrintReceipt1.exe" because it is being used by another process.
Hi, I have web Application,recently i am using crystal report to print report
ReplyDeletebut As per requirement I want to print report using min printer, so is it need to use different concept to print report
Thanks