C# winForm 打印Form 现在是能基本实现打印Form,但是我是希望达到如下效果打印的里面要有清晰的网格,包含label、textbox、下拉列表的等。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 设计报表,在报表中输入数据再打印屏幕截图打印也是种方法Rectangle R = System.Windows.Forms.Screen.PrimaryScreen.Bounds;Image img = new Bitmap(R.Width, R.Height);Graphics G = Graphics.FromImage(img);G.CopyFromScreen(new Point(0, 0), new Point(0, 0), new Size(R.Width, R.Height));。 IntPtr dc = G.GetHdc(); G.ReleaseHdc(dc);G.Dispose();img .Save("c:\\a.jpg");或private void DrawLabel(Label l, Graphics g) { Rectangle r = GetControlRect(l); if (l.AutoSize) { r.Width = (int)g.MeasureString(l.Text, l.Font).Width; } if (l.BorderStyle != BorderStyle.None) { g.DrawRectangle(_pen, r); } r.Width = (int)(r.Width * 1.1); r.Height = (int)(r.Height * 1.1); if (l.TextAlign == ContentAlignment.BottomRight || l.TextAlign == ContentAlignment.MiddleRight || l.TextAlign == ContentAlignment.TopRight) g.DrawString(GetControlText(l), l.Font, l.Enabled ? new SolidBrush(l.ForeColor) : Brushes.Gray, (RectangleF)r, new StringFormat(StringFormatFlags.DirectionRightToLeft)); else g.DrawString(GetControlText(l), l.Font, l.Enabled ? new SolidBrush(l.ForeColor) : Brushes.Gray, (RectangleF)r); } 直接打印Form我是实现了的,但是Form中不能显示网格啊,出来效果不行。水晶报表也想过,但是没用过,不知道能不能控件直接拖到里面,因为不只是这一张,画起来麻烦就不适用了。还有就是WPF,好像有网格,但是考虑到时间和难度就放弃了。DataGridView也考虑过,但是里面要加控件好像必须通过编程实现,MS不方便。里面嵌WebForm也想过,但是没成功。直接GDI+感觉太麻烦,也不适用。最后就是第三方控件,找了个FlexCell,看介绍能满足要求,但是好像又要收费!有没有人用过其他的介绍个?情况就是这么个情况,不知道还有没有好的建议?PS:怎么贴图上去呢?我想贴个效果图 combobox中item的值的问题 求助XmlReaderSettings和XmlValidatingReader进行xml与xsd文件校验时的问题 excel导入sql 临时表在C#的使用问题 在ListView里怎样获得从DataSet里的数据???? 菜鸟有几个删除语句想请教 关于接口写法的问题,希望路过的高人拉我一把~~谢谢先! sql 2008怎样修改实例名? 好问题?????? 怎样使RichTextBox按显示的内容来改变高度? 我又来提问了,关于数字格式 请教一个简单的控件问题
屏幕截图打印也是种方法
Rectangle R = System.Windows.Forms.Screen.PrimaryScreen.Bounds;
Image img = new Bitmap(R.Width, R.Height);
Graphics G = Graphics.FromImage(img);
G.CopyFromScreen(new Point(0, 0), new Point(0, 0), new Size(R.Width, R.Height));。
IntPtr dc = G.GetHdc();
G.ReleaseHdc(dc);
G.Dispose();
img .Save("c:\\a.jpg");
或
private void DrawLabel(Label l, Graphics g)
{
Rectangle r = GetControlRect(l);
if (l.AutoSize)
{
r.Width = (int)g.MeasureString(l.Text, l.Font).Width;
} if (l.BorderStyle != BorderStyle.None)
{
g.DrawRectangle(_pen, r);
}
r.Width = (int)(r.Width * 1.1);
r.Height = (int)(r.Height * 1.1);
if (l.TextAlign == ContentAlignment.BottomRight || l.TextAlign == ContentAlignment.MiddleRight || l.TextAlign == ContentAlignment.TopRight)
g.DrawString(GetControlText(l), l.Font, l.Enabled ? new SolidBrush(l.ForeColor) : Brushes.Gray, (RectangleF)r, new StringFormat(StringFormatFlags.DirectionRightToLeft));
else
g.DrawString(GetControlText(l), l.Font, l.Enabled ? new SolidBrush(l.ForeColor) : Brushes.Gray, (RectangleF)r);
}
水晶报表也想过,但是没用过,不知道能不能控件直接拖到里面,因为不只是这一张,画起来麻烦就不适用了。
还有就是WPF,好像有网格,但是考虑到时间和难度就放弃了。
DataGridView也考虑过,但是里面要加控件好像必须通过编程实现,MS不方便。
里面嵌WebForm也想过,但是没成功。
直接GDI+感觉太麻烦,也不适用。
最后就是第三方控件,找了个FlexCell,看介绍能满足要求,但是好像又要收费!有没有人用过其他的介绍个?
情况就是这么个情况,不知道还有没有好的建议?
PS:怎么贴图上去呢?我想贴个效果图