PDA

View Full Version : سوال: تنظیمات پرینتر



amin mohamadi
جمعه 20 مرداد 1391, 22:21 عصر
با سلام خدمت اساتید محترم
من توی برنامم از یه فرم عکس گرفتم و میخوام چاپ کنم
فقط یه مشکل دارم که جوابشو جایی پیدا نکردم
میخوام این عکس رو روی کاغذ A5 چاپ کنم بدون اینکه کاربر مجبور باشه خودش تنظیمات پرینترو انجام بده
یعنی خودم با کد نویسی paper size رو تغییر بدم و بفرستم برای پرینت

printDocument1.PrintPage += PDoc_PrintPage;
System.Drawing.Printing.PaperSize a = new System.Drawing.Printing.PaperSize("A5", 148, 210);
PageSettings ps = new PageSettings();
ps.PaperSize = a;
ps.Landscape = true;
ps.Margins.Top = 10;
ps.Margins.Bottom = 10;
ps.Margins.Left = 5;
ps.Margins.Right = 25;
printDocument1.OriginAtMargins = true;
printDocument1.DefaultPageSettings = ps;
printDocument1.Print();

همه چی درست کار میکنه جز a5

ali_habibi1384
جمعه 20 مرداد 1391, 23:29 عصر
تنظيم سايز پرينتر (http://msdn.microsoft.com/en-us/library/system.drawing.printing.pagesettings.papersize.asp x)

amin mohamadi
شنبه 21 مرداد 1391, 00:41 صبح
میشه دوباره چک کنید
من که نتونستم برم

amin mohamadi
شنبه 21 مرداد 1391, 00:51 صبح
اگه کسی پیدا بشه که کدشو بذاره ممنون میشم به همراه یکم توضیح
printDocument1.PrinterSettings.PaperSizes با این نمیشه انگار نمیشه تغییرش داد پیغام read only میده

ali_habibi1384
شنبه 21 مرداد 1391, 01:18 صبح
Help Msdn بود:


// Add list of supported paper sizes found on the printer.
// The DisplayMember property is used to identify the property that will provide the display string.
comboPaperSize.DisplayMember = "PaperName";

PaperSize pkSize;
for (int i = 0; i < printDoc.PrinterSettings.PaperSizes.Count; i++){
pkSize = printDoc.PrinterSettings.PaperSizes[i];
comboPaperSize.Items.Add(pkSize);
}

// Create a PaperSize and specify the custom paper size through the constructor and add to combobox.
PaperSize pkCustomSize1 = new PaperSize("First custom size", 100, 200);

comboPaperSize.Items.Add(pkCustomSize1);



...


// Add list of paper sources found on the printer to the combo box.
// The DisplayMember property is used to identify the property that will provide the display string.
comboPaperSource.DisplayMember="SourceName";

PaperSource pkSource;
for (int i = 0; i < printDoc.PrinterSettings.PaperSources.Count; i++){
pkSource = printDoc.PrinterSettings.PaperSources[i];
comboPaperSource.Items.Add(pkSource);
}


...


// Add list of printer resolutions found on the printer to the combobox.
// The PrinterResolution's ToString() method will be used to provide the display string.

PrinterResolution pkResolution;
for (int i = 0; i < printDoc.PrinterSettings.PrinterResolutions.Count; i++){
pkResolution = printDoc.PrinterSettings.PrinterResolutions[i];
comboPrintResolution.Items.Add(pkResolution);
}


...


private void MyButtonPrint_Click(object sender, System.EventArgs e)
{
// Set the paper size based upon the selection in the combo box.
if (comboPaperSize.SelectedIndex != -1) {
printDoc.DefaultPageSettings.PaperSize =
printDoc.PrinterSettings.PaperSizes[comboPaperSize.SelectedIndex];
}

// Set the paper source based upon the selection in the combo box.
if (comboPaperSource.SelectedIndex != -1) {
printDoc.DefaultPageSettings.PaperSource =
printDoc.PrinterSettings.PaperSources[comboPaperSource.SelectedIndex];
}

// Set the printer resolution based upon the selection in the combo box.
if (comboPrintResolution.SelectedIndex != -1)
{
printDoc.DefaultPageSettings.PrinterResolution=
printDoc.PrinterSettings.PrinterResolutions[comboPrintResolution.SelectedIndex];
}

// Print the document with the specified paper size, source, and print resolution.
printDoc.Print();
}

amin mohamadi
شنبه 21 مرداد 1391, 11:10 صبح
این کد کل سایز های پرینترو میگیره نمایش میده بعد باید یکیشو انتخاب کنی تا پرینت بگیره
تقریبا مثل printdialog
من میخوام بدون اینکه کاربر کاری بکنه تنظیمات انجام بشه

System.Drawing.Printing.PaperSize a = new System.Drawing.Printing.PaperSize("A5", 148, 210);
PageSettings ps = new PageSettings();
ps.PaperSize = a;
ps.Landscape = true;
ps.Margins.Top = 30;
ps.Margins.Bottom = 30;
ps.Margins.Left = 5;
ps.Margins.Right = 100;
printDocument1.OriginAtMargins = true;
printDocument1.DefaultPageSettings = ps;

همه چی درست کار میکنه فقط سایز کاغذ A5 نمیشه

amin mohamadi
شنبه 21 مرداد 1391, 12:08 عصر
درستش کردم فقط وقتی کار میکنه که پرینتر A5 رو ساپورت کنه
یعنی تو تنظیماتش داشته باشه
امیدوارم به درد یکی بخوره
پرینت از فرم و چاپ در کاغذ A5

private void PDoc_PrintPage(object sender, PrintPageEventArgs e)
{
this.FormBorderStyle = FormBorderStyle.None;
Bitmap bmp = new Bitmap(this.Width, this.Height);
this.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height));
e.Graphics.DrawImage(bmp, 10, 10);
e.Graphics.RotateTransform(90);
this.FormBorderStyle = FormBorderStyle.Fixed3D;
}
private void button8_Click(object sender, EventArgs e)
{
PrintDocument printDocument1 = new PrintDocument();
printDocument1.PrintPage += PDoc_PrintPage;

PageSettings ps = new PageSettings();

for (int i = 0; i < printDocument1.PrinterSettings.PaperSizes.Count; i++)
{
if (printDocument1.PrinterSettings.PaperSizes[i].Kind.ToString() == "A5")
{
ps.PaperSize = printDocument1.PrinterSettings.PaperSizes[i];
break;
}
}
ps.Landscape = true;
ps.Margins.Top = 30;
ps.Margins.Bottom = 30;
ps.Margins.Left = 20;
ps.Margins.Right = 50;
printDocument1.OriginAtMargins = true;
printDocument1.DefaultPageSettings = ps;
printDocument1.Print();

}