Friday 15 April 2016

c# form print & button style




using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;

namespace print
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public int month=1;
        public double balance_begin=10000, interest, payment = 888.49, balance_end;

        private void button1_Click(object sender, EventArgs e)
        {
           
            //printPreviewControl1.Document = this.printDocument1;
            printPreviewDialog1.Document = this.printDocument1;
            printPreviewDialog1.ShowDialog();

            printDialog1.ShowDialog();
            printDocument1.PrinterSettings.PrinterName = printDialog1.PrinterSettings.PrinterName;
            printDocument1.Print();
        }

        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            Font f = new Font(new FontFamily("arial"), 10, FontStyle.Regular);
            SolidBrush b = new SolidBrush(Color.Black);
            e.Graphics.DrawString("abc", f, b, 0, 0);

            int column = 0;
            int row = 15;

            e.Graphics.DrawString("month", f, b, column, row);
            e.Graphics.DrawString("begin", f, b, column + 100, row);
            e.Graphics.DrawString("interest", f, b, column+200, row);
            e.Graphics.DrawString("payment", f, b, column + 300, row);
            e.Graphics.DrawString("end", f, b, column+400, row);

            while (balance_begin > 0)
            {
                interest = balance_begin * 0.01;
                balance_end = balance_begin - interest - payment;

                e.Graphics.DrawString(month.ToString(), f, b, column, row*(month+1));
                string balance_begin_print = string.Format("{0,-10:f2}",balance_begin);
                e.Graphics.DrawString(balance_begin_print, f, b, column + 100, row *( month + 1));
                string interest_print = string.Format("{0,-10:f2}", interest);
                e.Graphics.DrawString(interest_print, f, b, column + 200, row*(month+1));
                e.Graphics.DrawString(payment.ToString(), f, b, column + 300, row*(month+1));
                string balance_end_print = string.Format("{0,-10:f2}", balance_end);
                e.Graphics.DrawString(balance_end_print, f, b, column + 400, row*(month+1));

                balance_begin = balance_end;
                month++;
            }

            e.HasMorePages = false;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            GraphicsPath g = new GraphicsPath();
            g.AddEllipse(new Rectangle(0, 0, button1.Size.Width, button1.Size.Height));
            button1.Region = new Region(g);
            button1.FlatStyle = FlatStyle.Flat;
            button1.FlatAppearance.BorderColor = Color.DarkGray;
            button1.BackColor = Color.DarkGray;
        }


    }
}

No comments:

Post a Comment