sharmila k

sharmila k

  • NA
  • 62
  • 51.6k

how to print image using print dialog controls in fixed position on form?

Aug 24 2012 3:43 AM
Hi Friend,

I create customer application Project in window application.
In that project i create one form as customer details.
After enter customer details i want to print that details using print dialog controls.
I got all details to print in fixed position on my form,expect customer photo.
How i can print customer photo in my fixed position on form.
Please any one give the Immediately solution.

This is my coding.
-------------------------------
 float ScreenResolution = 96.0f;

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            ScreenResolution = e.Graphics.DpiX;
        }

        void DrawForm(Graphics g, int resX, int resY)
        {
            g.FillRectangle(new SolidBrush(this.BackColor), 0, 0, this.Width, this.Height);
            float scale = resX / ScreenResolution;

            foreach (Control c in Controls)
            {
                string strType = c.GetType().ToString().Substring(c.GetType().ToString().LastIndexOf(".") + 1);
                switch (strType)
                {
                    case "Label":
                        //                        ControlPaint.FillReversibleRectangle( ((TextBox)c).Bounds, c.BackColor);
                        Label l = (Label)c;

                        ControlPaint.DrawButton(g, l.Left, l.Top, l.Width, l.Height, ButtonState.Pushed);
                        g.FillRectangle(new SolidBrush(l.BackColor), l.Left + 1, l.Top + 1, l.Width + 2, l.Height - 2);
                        g.DrawString(l.Text, l.Font, new SolidBrush(l.ForeColor), l.Left + 2, l.Top + l.Height / 2 - g.MeasureString("a", l.Font).Height / 2, new StringFormat());
                        break;
                    case "TextBox":
                        TextBox t = (TextBox)c;
                        ControlPaint.DrawButton(g, t.Left, t.Top, t.Width, t.Height, ButtonState.Pushed);
                        g.FillRectangle(new SolidBrush(t.BackColor), t.Left + 1, t.Top + 1, t.Width + 2, t.Height - 2);
                        g.DrawString(t.Text, t.Font, new SolidBrush(t.ForeColor), t.Left + 2, t.Top + t.Height / 2 - g.MeasureString("a", t.Font).Height / 2, new StringFormat());
                        break;

}

 private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            PrinterResolution pr = e.PageSettings.PrinterResolution;
            DrawForm(e.Graphics, pr.X, pr.Y);
        }



Answers (2)