PDA

View Full Version : پرینت فرم در سی شارپ



samirhm
سه شنبه 23 شهریور 1395, 12:51 عصر
سلام دوستان من یک button به نام print دارم که میخوام هر وقت کاربر اون دکمه رو زد از فرم یک پرینت بگیره ،، میخواستم ببینم که کدی رو باید بنویسم ؟

kamiloted
سه شنبه 23 شهریور 1395, 13:05 عصر
سلام دوستان من یک button به نام print دارم که میخوام هر وقت کاربر اون دکمه رو زد از فرم یک پرینت بگیره ،، میخواستم ببینم که کدی رو باید بنویسم ؟

سلام


using (Bitmap bm = new Bitmap(sz.Width, sz.Height))
{
Rectangle rect = new Rectangle(0, 0, sz.Width, sz.Height);
mp.DrawToBitmap(bm, rect);
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality ; // so footer is anti-aliased
e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQua lityBicubic; // so when we scale up, we smooth out the jaggies somewhat
e.Graphics.DrawImage(bm, this.MarginBounds, rect, GraphicsUnit.Pixel);
if (this.Footer != null)
e.Graphics.DrawImage(this.Footer, this.FooterLocation);
if (!string.IsNullOrEmpty(pageNumber))
{
e.Graphics.DrawString(pageNumber, KBStyle.Normal.Font, Brushes.Black,
this.MarginBounds.X, this.FooterLocation.Y + FooterOffset);
}
}



یا از این استفاده کن



private void button1_Click(object sender, EventArgs e)
{
PrintDocument doc = new PrintDocument();
doc.PrintPage += this.Doc_PrintPage;
PrintDialog dlgSettings = new PrintDialog();
dlgSettings.Document = doc;
if (dlgSettings.ShowDialog() == DialogResult.OK)
{
doc.Print();
}
}




private void Doc_PrintPage(object sender, PrintPageEventArgs e)
{
float x = e.MarginBounds.Left;
float y = e.MarginBounds.Top;
Bitmap bmp = new Bitmap(this.groupBox1.Width, this.groupBox1.Height);
this.groupBox1.DrawToBitmap(bmp, new Rectangle(0, 0, this.groupBox1.Width, this.groupBox1.Height));
e.Graphics.DrawImage((Image)bmp, x, y);
}

12457812
سه شنبه 23 شهریور 1395, 13:08 عصر
سلام
اموزشش خیلی تو نت زیاده فقط کافی بود سرچ کنید
روش های مختلفی وجود داره
که بهترینش میشه گفت استیمو سافت هستش
کافیه برنامشو دانلود کنید و نصب کنید
و بعد در سیشارپ کامپوننتشو اضافه کنید و شروع کنید به طراحی فرم خودتون
بعدش تو دکمه فراخوانی کنیدش
موفق باشی