PDA

View Full Version : سوال: چاپ کردن PictureBox



sohrabi1383
جمعه 06 دی 1392, 09:59 صبح
در کد زیر چگونه می توانیم عکس داخل PictureBox را در کنار «من به مدرسه رفتم» چاپ کنیم فایل ضمیمه برنامه را نیز فرستاده ام



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

namespace print4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}// public Form1()
private void button1_Click(object sender, EventArgs e)
{
PrintDocument objPrintDocument = new PrintDocument();
objPrintDocument.DocumentName = "student";
printDialog1.AllowPrintToFile = false;
printDialog1.AllowSelection = false;
printDialog1.AllowSomePages = false;
printDialog1.Document = objPrintDocument;
if (printDialog1.ShowDialog() == DialogResult.OK)
{
objPrintDocument.PrintPage += new PrintPageEventHandler(prtPage);
objPrintDocument.Print();
}//if (printDialog1.ShowDialog() == DialogResult.OK)
}// private void button1_Click(object sender, EventArgs e)
private void prtPage(object sender, PrintPageEventArgs e)
{
string drawString = "من به مدرسه رفتم.";
SolidBrush drawBrush = new SolidBrush(Color.Black);
Font drawFont = new System.Drawing.Font("Arail", 10);
RectangleF recAtZero = new RectangleF(0, 0, e.PageBounds.Width, e.PageBounds.Height );
StringFormat drawFormat = new StringFormat();
drawFormat.FormatFlags = StringFormatFlags.DirectionRightToLeft;
e.Graphics.DrawString(drawString, drawFont, drawBrush, recAtZero, drawFormat);
RectangleF recAtGreaterThantZero = new RectangleF(300, 0, e.PageBounds.Width, e.PageBounds.Height );
e.Graphics.DrawString(drawString, drawFont, drawBrush, recAtGreaterThantZero, drawFormat);
}//private void prtPage(object sender, PrintPageEventArgs e)
}// public partial class Form1 : Form
}//namespace print4

sohrabi1383
سه شنبه 17 دی 1392, 21:47 عصر
باید از کد زیر برای چاپ pictureBox استفاده کنیم.


e.Graphics.DrawImage(pictureBox1.Image,0,0,52,63);

که 52 و 63 ارتفاع و طول عکس در چاپ هستند.

khokhan
سه شنبه 17 دی 1392, 22:44 عصر
در کد زیر چگونه می توانیم عکس داخل PictureBox را در کنار «من به مدرسه رفتم» چاپ کنیم فایل ضمیمه برنامه را نیز فرستاده ام






این لینک (http://www.c-sharpcorner.com/UploadFile/9f4ff8/print-the-window-form-print-the-image-of-picture-box/) رو ببین