Current location: Hot Scripts Forums » Programming Languages » Windows .NET Programming » [SOLVED] printing in C#.net


[SOLVED] printing in C#.net

Reply
  #1 (permalink)  
Old 08-04-08, 06:33 AM
varun_mca_ju's Avatar
varun_mca_ju varun_mca_ju is offline
Newbie Coder
 
Join Date: Jul 2008
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Question [SOLVED] printing in C#.net

i have a C# windows application in Visual Studio. I have a form which is opened in a panel.i want to print the data in various controls of the form upon clicking a PRINT button.but i don't want to print the jpg image of the entire form or any of its controls.i want that the text in the controls should be printed.for e.g. i have a label NAME:- and a textbox txtName in front of the label and suppose the user enters the name john in the textbox . iwant that they should be printed as follows:
NAME:- john
the enitre label and text box should not be printed but only the text in them should be printed.....is there any way to do it....is there any alternative way like adding the data in textbox and label to an MS Word document and then printing the document...plz. help...thanx in advance.
Reply With Quote
  #2 (permalink)  
Old 08-05-08, 03:24 PM
digioz's Avatar
digioz digioz is offline
Community VIP
 
Join Date: Oct 2003
Location: Chicago, IL
Posts: 2,171
Thanks: 3
Thanked 9 Times in 9 Posts
Why not just grab the label and textbox text and create a print document to do what you want?


Pete
__________________
Reply With Quote
  #3 (permalink)  
Old 08-06-08, 01:46 AM
varun_mca_ju's Avatar
varun_mca_ju varun_mca_ju is offline
Newbie Coder
 
Join Date: Jul 2008
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Question ??printing in C#.net??

thanks for the reply digioz.....could you please give me the code ....as i am new to c#.net programming(infact i am a novice)....so kind of u
Reply With Quote
  #4 (permalink)  
Old 08-08-08, 01:15 AM
varun_mca_ju's Avatar
varun_mca_ju varun_mca_ju is offline
Newbie Coder
 
Join Date: Jul 2008
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
i've got the solution to this problem....the coding is given below:-
csharp Code:
  1. using System.Drawing.Printing;
  2. using System.Drawing;
  3. using System.IO;
  4.  
  5. namespace WindowsApplication1
  6. {
  7.  
  8.     public partial class Form3 : Form
  9.     {
  10.       private System.ComponentModel.Container components;
  11.         private System.Windows.Forms.Button printButton;
  12.          private Font printFont;
  13.           private StreamReader streamToPrint;
  14.         PrintDocument printDocument1 = new PrintDocument();
  15.  
  16.  
  17.         public Form3()
  18.         {
  19.             InitializeComponent();
  20.            
  21.           printDocument1.PrintPage += printDocument1_PrintPage;
  22.         }
  23.  
  24.   private void printButton_Click(object sender, EventArgs e)
  25.         {
  26.           using (PrintDialog pd = new PrintDialog())
  27.             {
  28.                 if (pd.ShowDialog() == DialogResult.OK)
  29.                                     printDocument1.PrinterSettings = pd.PrinterSettings;
  30.                     printDocument1.Print();
  31.                 }
  32.  
  33.  
  34.  void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
  35.         {
  36.                        Font objFont=new Font ("Microsoft Sans Serif", 10F);//sets the font type and size
  37.             float fTopMargin = e.MarginBounds.Top;
  38.             float fLeftMargin = 50;//sets left margin
  39.             float fRightMargin = e.MarginBounds.Right - 150;//sets right margin   
  40. string employee_id = String.Concat("EMPLOYEE ID:-  ", comboBox2.Text);//prints EMPLOYEE ID:- and text in combobox2
  41.       string employee_name = String.Concat("EMPLOYEE NAME:-  ", textBox8.Text);
  42.  
  43. e.Graphics.DrawString(employee_id, objFont, Brushes.Black, fLeftMargin, fTopMargin);
  44.            
  45.  fTopMargin += objFont.GetHeight() * 2;//skip two lines
  46.            
  47.  e.Graphics.DrawString(employee_name, objFont, Brushes.Black, fLeftMargin, fTopMargin);
  48.          
  49.  objFont.Dispose();
  50.            
  51.  e.HasMorePages = false;
  52.         }

Last edited by Nico; 08-08-08 at 02:31 AM.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Printing in a dot matrix printer changes the top margin and left margin Ork Visual Basic 4 02-18-06 11:35 AM
Printing Tickets phppick PHP 3 06-16-05 04:03 AM
Printing Event? Naresh Rohra Visual Basic 2 09-24-04 04:15 PM
Automated Digital Printing System amberpro Job Offers & Assistance 1 07-10-04 06:22 PM
essential business & printing supplies digital print General Advertisements 0 03-29-04 06:05 AM


All times are GMT -5. The time now is 02:17 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.