• Web sitemizin içeriğine ve tüm hizmetlerimize erişim sağlamak için Web sitemize kayıt olmalı ya da giriş yapmalısınız. Web sitemize üye olmak tamamen ücretsizdir.
  • Sohbetokey.com ile canlı okey oynamaya ne dersin? Hem sohbet et, hem mobil okey oyna!
  • Soru mu? Sorun mu? ''Bir Sorum Var?'' sistemimiz aktiftir. Paylaşın beraber çözüm üretelim.
Bu, hızlı yüklenen mobil optimize edilmiş bir AMP sayfadır, gerçek sayfayı yüklemek istiyorsanız bu metni tıklayın.

Resource File Yazdırma - C Sharp Applications Print Resource Text ********

Üyelik Tarihi
7 Ocak 2015
Konular
4,091
Mesajlar
4,274
MFC Puanı
40
Kod:
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.IO;
using System.Drawing.Printing;
using System.Reflection;

namespace Print********File
{
    public partial class Form1 : Form
    {
        OpenFileDialog openfiledialog;
        StreamReader filereader;
        Print******** print********;
        PrintPreviewDialog printPreviewDialog;
        Font ArialFont;
        List fileLineList;

        public Form1()
        {
            InitializeComponent();
        }

        private **** Form1_Load(object sender, EventArgs e)
        {
            //dosyadan alınacak satırları tutacak bir liste oluştur

            fileLineList = new List< string >();

            // Create openfile dialog object.

            openfiledialog = new OpenFileDialog();
            openfiledialog.Title = "C Sharp Applications Open File Dialog";
            openfiledialog.InitialDirectory = Application.StartupPath;
            openfiledialog.Filter = "Text files (*.txt) | .txt | All files (*.*) | *.*";
            openfiledialog.FilterIndex = 2;
            openfiledialog.RestoreDirectory = true;

            //Create a Arial font with size 12

            ArialFont = new Font("Arial",12);

            //Create a Print******** object

            print******** = new Print********();

            printPreviewDialog = new PrintPreviewDialog();

            //Add PrintPage event handler 

            print********.PrintPage += new PrintPageEventHandler(print********_PrintPage);
            print********.BeginPrint += new PrintEventHandler(print********_BeginPrint);
            print********.EndPrint += new PrintEventHandler(print********_EndPrint);
        }

        **** print********_EndPrint(object sender, PrintEventArgs e)
        {
            lblStatus.Text = "The ******** is printed ";
        }

        **** print********_BeginPrint(object sender, PrintEventArgs e)
        {
            lblStatus.Text = "Printing is completed ";
        }

        private **** btnPrint_Click(object sender, EventArgs e)
        {
            totalLinecount = 0;

            //Call Print Method

            print********.Print();

            //Close the reader

            if (filereader != null)
            {
                filereader.Close();
            }
        }


        int totalLinecount = 0;

        private **** print********_PrintPage(object sender, PrintPageEventArgs printpageevent)
        {
            //Get the Graphics object from the print page event

            Graphics g = printpageevent.Graphics;
            
            float linesPerPage = 0;
            
            float yposition = 0;

            int pageLineCount = 0;
            
            float leftMargin = printpageevent.MarginBounds.Left;

            float topMargin = printpageevent.MarginBounds.Top;
           
           
            //Calculate the lines per page on the basis of the height of the page and the height of the font
          
            linesPerPage = printpageevent.MarginBounds.Height / ArialFont.GetHeight(g);
            
            //Now read lines one by one, using StreamReader

            while (pageLineCount < linesPerPage && totalLinecount < fileLineList.Count)
            {
                //Calculate the starting position

                yposition = topMargin + (pageLineCount * ArialFont.GetHeight(g));
              
                //Draw text
              
                g.DrawString(fileLineList[totalLinecount], ArialFont, Brushes.Black, leftMargin, yposition, new StringFormat());
                
                //Move to next line
                totalLinecount++;
                pageLineCount++;
            }
            //If PrintPageEventArgs has more pages to print

            if (totalLinecount < fileLineList.Count)
            {
                printpageevent.HasMorePages = true;
            }
            else
            {
                printpageevent.HasMorePages = false;
            }
        }

        private **** btnBrowse_Click(object sender, EventArgs e)
        {
            if (openfiledialog.ShowDialog() == DialogResult.OK)
            {
                //okunan satırların saklanacağı listeyi temizle

                fileLineList.Clear();

                //textbox1 içinde açılan dosyanın adresini yazdıralım

                textBox1.Text = openfiledialog.FileName;

                string filename = textBox1.Text.ToString();

                //Create a StreamReader object for reading file contents

                filereader = new StreamReader(filename);

                string satir;

                while ((satir = filereader.ReadLine()) != null)
                {
                    //dosyadan okunan satırları listeye ekleyelim

                    fileLineList.Add(satir);
                }
            }
        }

        private **** btnOnizleme_Click(object sender, EventArgs e)
        {
            printPreviewDialog.******** = print********;
            printPreviewDialog.ShowDialog();
        }

        private **** btnResourceFilePrint_Click(object sender, EventArgs e)
        {
            totalLinecount = 0;

            Assembly assembly =  Assembly.GetExecutingAssembly();
            Stream stream = assembly.GetManifestResourceStream("Print********File.Resources.My********.txt");
            StreamReader reader = new StreamReader(stream);

            string satir;

            //okunan satırların saklanacağı listeyi temizle

            fileLineList.Clear();

            while ((satir = reader.ReadLine()) != null)
            {
                //dosyadan okunan satırları listeye ekleyelim

                fileLineList.Add(satir);
            }

            //Call Print Method

            print********.Print();

        }
    }
}
 

Ahtapot

MFC Üyesi
Üyelik Tarihi
14 Ocak 2015
Konular
1
Mesajlar
42
MFC Puanı
0
Güzel Pyalaşım Ellerine Sağlık ...