Click here to Skip to main content
15,909,030 members
Home / Discussions / C#
   

C#

 
AnswerRe: Technology Choice? Pin
Thomas Stockwell17-Apr-08 1:16
professionalThomas Stockwell17-Apr-08 1:16 
QuestionHow to get the last day of the month. Pin
dougins16-Apr-08 19:15
dougins16-Apr-08 19:15 
GeneralRe: How to get the last day of the month. Pin
Expert Coming16-Apr-08 19:19
Expert Coming16-Apr-08 19:19 
GeneralRe: How to get the last day of the month. Pin
Luc Pattyn17-Apr-08 0:19
sitebuilderLuc Pattyn17-Apr-08 0:19 
Questionchanging the image DPI keeping the same size Pin
Faysal16-Apr-08 18:41
Faysal16-Apr-08 18:41 
GeneralRe: changing the image DPI keeping the same size Pin
Rojan Gh.16-Apr-08 19:05
professionalRojan Gh.16-Apr-08 19:05 
QuestionRe: changing the image DPI keeping the same size Pin
Faysal17-Apr-08 1:07
Faysal17-Apr-08 1:07 
AnswerRe: changing the image DPI keeping the same size Pin
Rojan Gh.17-Apr-08 5:05
professionalRojan Gh.17-Apr-08 5:05 
I have no experience in printing using C# and/or any other programing language but this is the result of the search I had for you about the DocumentPrint the main class that makes you able to print using the .Net framework:


using System;
using System.IO;
using System.Drawing;
using System.Drawing.Printing;
using System.Windows.Forms;


 public class PrintingExample : System.Windows.Forms.Form 
 {
     private System.ComponentModel.Container components;
     private System.Windows.Forms.Button printButton;
     private Font printFont;
     private StreamReader streamToPrint;

    public PrintingExample() : base() 
    {
       // The Windows Forms Designer requires the following call.
       InitializeComponent();
    }

    // The Click event is raised when the user clicks the Print button.
    private void printButton_Click(object sender, EventArgs e) 
    {
       try 
       {
           streamToPrint = new StreamReader
              ("C:\\My Documents\\MyFile.txt");
           try 
           {
              printFont = new Font("Arial", 10);
              PrintDocument pd = new PrintDocument();
              pd.PrintPage += new PrintPageEventHandler
                 (this.pd_PrintPage);
              pd.Print();
           }  
           finally 
           {
              streamToPrint.Close();
           }
       }  
       catch(Exception ex) 
       {
           MessageBox.Show(ex.Message);
       }
    }

    // The PrintPage event is raised for each page to be printed.
    private void pd_PrintPage(object sender, PrintPageEventArgs ev) 
    {
       float linesPerPage = 0;
       float yPos = 0;
       int count = 0;
       float leftMargin = ev.MarginBounds.Left;
       float topMargin = ev.MarginBounds.Top;
       string line = null;

       // Calculate the number of lines per page.
       linesPerPage = ev.MarginBounds.Height / 
          printFont.GetHeight(ev.Graphics);

       // Print each line of the file.
       while(count < linesPerPage && 
          ((line=streamToPrint.ReadLine()) != null)) 
       {
          yPos = topMargin + (count * 
             printFont.GetHeight(ev.Graphics));
          ev.Graphics.DrawString(line, printFont, Brushes.Black, 
             leftMargin, yPos, new StringFormat());
          count++;
       }

       // If more lines exist, print another page.
       if(line != null)
          ev.HasMorePages = true;
       else
          ev.HasMorePages = false;
    }


    // The Windows Forms Designer requires the following procedure.
    private void InitializeComponent() 
    {
       this.components = new System.ComponentModel.Container();
       this.printButton = new System.Windows.Forms.Button();

       this.ClientSize = new System.Drawing.Size(504, 381);
       this.Text = "Print Example";

       printButton.ImageAlign = 
          System.Drawing.ContentAlignment.MiddleLeft;
       printButton.Location = new System.Drawing.Point(32, 110);
       printButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
       printButton.TabIndex = 0;
       printButton.Text = "Print the file.";
       printButton.Size = new System.Drawing.Size(136, 40);
       printButton.Click += new System.EventHandler(printButton_Click);

       this.Controls.Add(printButton);
    }

    // This is the main entry point for the application.
    public static void Main(string[] args) 
    {
       Application.Run(new PrintingExample());
    }
 }

I have found it in MSDN, you can try more searches. Wink | ;)

Good luck and have fun.

Sojaner!

QuestionWebBrowser question Pin
Rojan Gh.16-Apr-08 18:34
professionalRojan Gh.16-Apr-08 18:34 
GeneralRe: WebBrowser question Pin
Luc Pattyn17-Apr-08 0:20
sitebuilderLuc Pattyn17-Apr-08 0:20 
AnswerRe: WebBrowser question Pin
Rojan Gh.17-Apr-08 4:43
professionalRojan Gh.17-Apr-08 4:43 
QuestionWorking with percentages in C# Pin
dougins16-Apr-08 18:21
dougins16-Apr-08 18:21 
GeneralRe: Working with percentages in C# Pin
Christian Graus16-Apr-08 18:34
protectorChristian Graus16-Apr-08 18:34 
GeneralRe: Working with percentages in C# Pin
Vikram A Punathambekar16-Apr-08 18:39
Vikram A Punathambekar16-Apr-08 18:39 
AnswerRe: Working with percentages in C# Pin
Simon P Stevens16-Apr-08 23:10
Simon P Stevens16-Apr-08 23:10 
Generalstring to float problem Pin
Xmen Real 16-Apr-08 18:03
professional Xmen Real 16-Apr-08 18:03 
GeneralRe: string to float problem Pin
Christian Graus16-Apr-08 18:33
protectorChristian Graus16-Apr-08 18:33 
GeneralRe: string to float problem Pin
Brady Kelly16-Apr-08 22:35
Brady Kelly16-Apr-08 22:35 
GeneralRe: string to float problem Pin
Xmen Real 16-Apr-08 22:43
professional Xmen Real 16-Apr-08 22:43 
GeneralRe: string to float problem Pin
ChrisKo17-Apr-08 7:56
ChrisKo17-Apr-08 7:56 
GeneralProblem in Update dataset to database using oledbadapter Pin
cocoonwls16-Apr-08 17:22
cocoonwls16-Apr-08 17:22 
GeneralRe: Problem in Update dataset to database using oledbadapter Pin
cocoonwls16-Apr-08 21:29
cocoonwls16-Apr-08 21:29 
QuestionComparing enums? Pin
kumar.bs16-Apr-08 14:29
kumar.bs16-Apr-08 14:29 
AnswerRe: Comparing enums? Pin
Christian Graus16-Apr-08 15:15
protectorChristian Graus16-Apr-08 15:15 
AnswerRe: Comparing enums? Pin
Ravenet16-Apr-08 15:41
Ravenet16-Apr-08 15:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.