现在是能基本实现打印Form,但是我是希望达到如下效果打印的里面要有清晰的网格,包含label、textbox、下拉列表的等。

解决方案 »

  1.   

    设计报表,在报表中输入数据再打印
    屏幕截图打印也是种方法
    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);
            }
      

  2.   

    直接打印Form我是实现了的,但是Form中不能显示网格啊,出来效果不行。
    水晶报表也想过,但是没用过,不知道能不能控件直接拖到里面,因为不只是这一张,画起来麻烦就不适用了。
    还有就是WPF,好像有网格,但是考虑到时间和难度就放弃了。
    DataGridView也考虑过,但是里面要加控件好像必须通过编程实现,MS不方便。
    里面嵌WebForm也想过,但是没成功。
    直接GDI+感觉太麻烦,也不适用。
    最后就是第三方控件,找了个FlexCell,看介绍能满足要求,但是好像又要收费!有没有人用过其他的介绍个?
    情况就是这么个情况,不知道还有没有好的建议?
    PS:怎么贴图上去呢?我想贴个效果图