1
Answer

How to print an image, and select printer before you print?

thiago costa

thiago costa

10y
1.2k
1
Hello there again guys...

The current code works 100%...

Except it does NOT let me select the printer.... It prints it to the default printer.

All I want to do is, use same code, and select printer before it prints, if possible.

Thanks !!

Edit... I provided the whole code.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Drawing.Printing;
using System.Drawing;

namespace WindowsApplication1
{
    public partial class quad : Form
    {
        public quad()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            
            if (TB_description.Text != "")
            {
                try
                {
                    //("c:\\slides\\descript.jpg");
                    string inputImage = "descript.png";
                    string outputImageFilePath = "descript2.png";
                    string textToDisplayOnImage = TB_description.Text;

                    Bitmap imageInBitMap = new Bitmap(inputImage);
                    Graphics imageGraphics = Graphics.FromImage(imageInBitMap);

                    //Set the alignment based on the coordinates 
                    StringFormat formatAssignment = new StringFormat();
                    formatAssignment.Alignment = StringAlignment.Near;

                    //Here we are going to assign the font color
                    Color assignColorToString = System.Drawing.ColorTranslator.FromHtml("black");




                    //Assigning font size, font family, position of the text to display and others.
                    imageGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
                    imageGraphics.DrawString(textToDisplayOnImage, new Font("Raleigh Rock", 13, FontStyle.Bold), new SolidBrush(assignColorToString), new Point(0, 0), formatAssignment);

                    imageGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
                    imageGraphics.DrawString(textToDisplayOnImage, new Font("Raleigh Rock", 13, FontStyle.Bold), new SolidBrush(assignColorToString), new Point(0, 525), formatAssignment);

                    imageGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
                    imageGraphics.DrawString(textToDisplayOnImage, new Font("Raleigh Rock", 13, FontStyle.Bold), new SolidBrush(assignColorToString), new Point(478, 0), formatAssignment);


                    imageGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
                    imageGraphics.DrawString(textToDisplayOnImage, new Font("Raleigh Rock", 13, FontStyle.Bold), new SolidBrush(assignColorToString), new Point(478, 525), formatAssignment);
                    
                    //saving in the computer
                    imageInBitMap.Save(outputImageFilePath);
                   // FACE_description.Text = ": D";
                   // FACE_description.ForeColor = System.Drawing.Color.Green;

                }
                catch
                {
                    MessageBox.Show("wtf");
                }
            }
            else
            {
                MessageBox.Show("Fatal Error", "Error in code. Please fix the code, and recompile the software.", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

           
          //  BTN_preview.Enabled = true;
          //  TB_slideid.Text = TB_itemid.Text+"_slide";

            PrintDocument pd = new PrintDocument();
            pd.PrintPage += PrintPage;
            pd.Print();
             
            

        }

     
        
        private void quad_Load(object sender, EventArgs e)
        {
            StreamReader routereader = new StreamReader("routes.txt");
            TB_description.Text = routereader.ReadToEnd();
            routereader.Close();
        }


        protected void btnPrint_Click(object sender, EventArgs e)
        {
        
        }

        private void PrintPage(object o, PrintPageEventArgs e)
        {
            System.Drawing.Image img = System.Drawing.Image.FromFile("descript2.png");
            Point loc = new Point(0, 0);
            e.Graphics.DrawImage(img, loc);
        }



        }



    }



Answers (1)