Windows窗体中的打印面板C#
发布时间:2020-12-14 05:47:08 所属栏目:Windows 来源:网络整理
导读:我有一个情况.我需要在Visual Studio 2010中使用C#以 Windows窗体创建员工卡结构.该结构可能包含带有白色背景的标签和图片框.我没有创建它的问题,但我也在这个表单上给出一个名为“打
我有一个情况.我需要在Visual Studio 2010中使用C#以
Windows窗体创建员工卡结构.该结构可能包含带有白色背景的标签和图片框.我没有创建它的问题,但我也在这个表单上给出一个名为“打印”的按钮,以便用户可以打印该卡.我用谷歌搜索,但没有找到具体的东西.
请帮帮我. namespace Employee_Card_Manager { public partial class Card : Form { public Card(String a,String b,String c,String d,String e,String f,String g,String h,String i) { InitializeComponent(); this.label2.Text = a; this.label9.Text = b; this.label10.Text = c; this.label11.Text = d; this.label12.Text = e; this.label13.Text = f; this.label14.Text = g; this.label16.Text = h; this.pictureBox1.Image = Image.FromFile(i); Image myimg = Code128Rendering.MakeBarcodeImage(h,2,true); this.pictureBox2.Image = myimg; } private void button1_Click(object sender,EventArgs e) { //Print Card Code } } } 卡片模板如下: 我已将所有卡片结构放在Panel Control上,并将Panel背景设置为白色.你能填写打印这张卡的代码吗? 解决方法
我发现以下代码工作正常!!
//declare event handler for printing in constructor printdoc1.PrintPage += new PrintPageEventHandler(printdoc1_PrintPage); //Rest of the code Bitmap MemoryImage; public void GetPrintArea(Panel pnl) { MemoryImage = new Bitmap(pnl.Width,pnl.Height); pnl.DrawToBitmap(MemoryImage,new Rectangle(0,pnl.Width,pnl.Height)); } protected override void OnPaint(PaintEventArgs e) { if (MemoryImage != null) { e.Graphics.DrawImage(MemoryImage,0); base.OnPaint(e); } } void printdoc1_PrintPage(object sender,PrintPageEventArgs e) { Rectangle pagearea = e.PageBounds; e.Graphics.DrawImage(MemoryImage,(pagearea.Width / 2) - (this.panel1.Width / 2),this.panel1.Location.Y); } public void Print(Panel pnl) { pannel = pnl; GetPrintArea(pnl); previewdlg.Document = printdoc1; previewdlg.ShowDialog(); } private void button1_Click(object sender,EventArgs e) { Print(this.panel1); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- windows – 使用希腊语文本编译.Rnw到pdf
- iis – 在Windows Server上使用的FTP服务?
- windows – 用于登录用户的sAMAccountName
- windows-phone-7 – 在横向中剪裁键盘的原因
- windows-store-apps – 如何使用滑动动画以编程方式在FlipV
- 在Windows Azure网站上运行哪个版本的node.js?
- 如何在Windows Vista上编译为Linux / Unix编写的C源代码(给
- 事后崩溃转储调试没有在Symbol Server中具有Windows DLL的确
- windows – “相对虚拟地址”,相对于什么?
- windows api(GDI)实现图片旋转
推荐文章
站长推荐
热点阅读