Click here to Skip to main content
15,887,853 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
hello every one.

I little speak English.
My problem;
Picture Format: Bmp
Picture Pixels:895*842
How can i resize a image for Printer in c#.

My Pc : 1280*1024 --PictureBox image pixels 895*842 for A4 pixels
printer priview small.But program screen good.
I using picture box Dock.

my friends leptop ; 1366*768
I using print button but my buttons and textboxes in different locations.and my image very small for printer.
My for need A4 Paper Full Screen and all Pc and Resolution.

thanks you for all

I Using Print Code:
C#
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.Design;
using System.Drawing.Printing;

C#
Bitmap bmp = new System.Drawing.Bitmap("C:\\r\\picture.bmp");

C#
private void Form1_Load(object sender, EventArgs e)
        {          
            pictureBox1.Size = new System.Drawing.Size(895,842);
            pictureBox1.Image = bmp;
            
        }


C#
private void pd_PrintPage(object sender,System.Drawing.Printing.PrintPageEventArgs e)

        {
            e.Graphics.DrawImage(pictureBox1.Image, 0, 0);
        }

C#
System.Drawing.Printing.PrintDocument myPrintDocument1 = new System.Drawing.Printing.PrintDocument();

PrintDialog myPrinDialog1 = new PrintDialog();

myPrintDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(myPrintDocument2_PrintPage);



myPrinDialog1.Document = myPrintDocument1;



if (myPrinDialog1.ShowDialog() == DialogResult.OK)
{

myPrintDocument1.Print();
} 

C#
private void myPrintDocument2_PrintPage(System.Object sender, System.Drawing.Printing.PrintPageEventArgs e)
{

Bitmap myBitmap1 = new Bitmap(pictureBox1.Width, pictureBox1.Height);

pictureBox1.DrawToBitmap(myBitmap1, new Rectangle(0, 0, pictureBox1.Width, pictureBox1.Height));

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

myBitmap1.Dispose();

}
Posted

1 solution

To change the picture size depending on the form size when using a docked picturebox I would add the bold line below to your code.
C#
private void Form1_Load(object sender, EventArgs e)
{
    pictureBox1.Size = new System.Drawing.Size(895,842);
    pictureBox1.Image = bmp;
    PictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
}

For resizing the picture, there is a nice article here at Code Project which describes some methods for resizing pictures here: Resizing an Image On-The-Fly using .NET[^]

If you don't want your buttons and other controls moving around depending on the screen resolution you can read this article at MSDN:How To Create a Resolution-Independent Form[^]

Good luck!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900