Yazı Font Küçült Yazı Font Büyült

DataGridView Nesnesini Yazdırma

 

Merhaba arkadaşlar. Bu makalede DataGridView nesnesindeki bilgileri yazdıracağız.

 

 

Form1.cs

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Data.SqlClient;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

 

namespace WindowsFormsApplication1

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

 

        private void Form1_Load(object sender, EventArgs e)

        {

            SqlConnection baglan = new SqlConnection("Data Source=(LocalDB)\\v11.0;AttachDbFilename=|DataDirectory|\\personel.mdf;Integrated Security=True;Connect Timeout=30");

            SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM [dbo].[Table]", baglan);

            DataSet ds = new DataSet();

           

            baglan.Open();

            da.Fill(ds, "Table");

            baglan.Close();

 

            dataGridView1.DataSource = ds;

            dataGridView1.DataMember = "Table";

        }

 

        private void button1_Click(object sender, EventArgs e)

        {

            printDocument1.Print();

        }

 

        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)

        {

            //datagridview daki bilgileri yazdırıyoruz.

            Bitmap bmap = new Bitmap(dataGridView1.Width, dataGridView1.Height);

            dataGridView1.DrawToBitmap(bmap, new Rectangle(0, 0, dataGridView1.Width, dataGridView1.Height));

            e.Graphics.DrawImage(bmap, 0, 0);

        }

    }

}

 

Bir makalenin daha sonuna geldik. Bir sonraki makalede görüşmek üzere. Bahadır ŞAHİN