Kreiranje Print dokumenta

1. Iz Toolbox-a prevucite OpenFileDialog kutiju na formu. 2. U Properties prozoru stavite osobinu Filter od OpenFileDialog1 u Text Files | *.txt. 3. Ispod FileMenuItem-a, dodajte meni stavku koja se zove Open File. 4. Dvaput kliknite na OpenFileToolStripMenuItem da otvorite kod editor OpenFileToolStripMenuItem_Click event handler-a. 5. Van OpenFileToolStripMenuItem_Click event handler-a dodajte sledeći kod: string s; string[] strings; int ArrayCounter = 0; 6. Unutar OpenFileToolStripMenuItem_Click event handler-a dodajte sledeći kod: System.Windows.Forms.DialogResult aResult; aResult = openFileDialog1.ShowDialog(); if (aResult == System.Windows.Forms.DialogResult.OK) { System.IO.StreamReader aReader = new System.IO.StreamReader(openFileDialog1.FileName); s = aReader.ReadToEnd(); aReader.Close(); strings = s.Split('\n'); } 7. Unutar PrintDocument1_PrintPage event handler-a, zamenite postojeći kod sledećim: float LeftMargin = e.MarginBounds.Left; float TopMargin = e.MarginBounds.Top; float MyLines = 0; float YPosition = 0; int Counter = 0; string CurrentLine; MyLines = e.MarginBounds.Height / this.Font.GetHeight(e.Graphics); while (Counter < MyLines && ArrayCounter <= strings.Length - 1) { CurrentLine = strings[ArrayCounter]; YPosition = TopMargin + Counter * this.Font.GetHeight(e.Graphics); e.Graphics.DrawString(CurrentLine, this.Font, Brushes.Black,

GetLength(0) . YPosition. ArrayCounter++. } if (!(ArrayCounter >= strings. . 8.1)) e.LeftMargin. Counter++. else e. Ištampajte fajl. new StringFormat()). Pritisnite F8 da pokrenete aplikaciju.HasMorePages = true. Izaberite Print Preview iz File menija da vidite fajl u Print Preview dialog box-u.HasMorePages = false. Izaberite Open File iz fajl menija i izaberite tekst fajl sa vašeg kompjutera.

Sign up to vote on this title
UsefulNot useful