日期:2014-05-19  浏览次数:20967 次

WinForm中如何实现打印特定区域,如何合并DataGrid的单元格?请教高手!!!
WinForm中如何实现打印特定区域,如何合并DataGrid的单元格?请教高手!!!


------解决方案--------------------
[System.Runtime.InteropServices.DllImport( "gdi32.dll ")]
public static extern long BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
ArrayList arry;
ArrayList arry2;
Bitmap memoryImage;
private void Form1_Load(object sender, EventArgs e)
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.axBarCodeCtrl1 = new AxBARCODELib.AxBarCodeCtrl();
this.axBarCodeCtrl1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject( "axBarCodeCtrl1.OcxState ")));
arry = new ArrayList();
arry2 = new ArrayList();
printDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(printDocument1_PrintPage);
panel1.Paint += new PaintEventHandler(panel1_Paint);
}

void panel1_Paint(object sender, PaintEventArgs e)
{
for (int i = 0; i < arry.Count; i++)
{
e.Graphics.DrawImage(((Bitmap)arry[i]), ((Point)arry2[i]));
}
}

void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{



e.Graphics.DrawImage(memoryImage,0,0);
}

private void button2_Click(object sender, EventArgs e)
{
Size s = panel1.Size;
Graphics mygraphics;
Graphics memoryGraphics;
IntPtr dc1;
IntPtr dc2;
foreach (Control c in panel1.Controls)
{

mygraphics = c.CreateGraphics();
s = c.Size;
memoryImage = new Bitmap(s.Width, s.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
memoryGraphics = Graphics.FromImage(memoryImage);
dc1 = mygraphics.GetHdc();
dc2 = memoryGraphics.GetHdc();
BitBlt(dc2, 0, 0, c.ClientRectangle.Width, c.ClientRectangle.Height, dc1, 0, 0, 13369376);
mygraphics.ReleaseHdc(dc1);
memoryGraphics.ReleaseHdc(dc2);
arry.Add(memoryImage);
Point p = new Point(c.Location.X,c.Location.Y);
arry2.Add(p);
}
this.Refresh();
mygraphics = panel1.CreateGraphics();
s = panel1.Size;
memoryImage = new Bitmap(s.Width, s.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
memoryGraphics = Graphics.FromImage(memoryImage);
dc1 = mygraphics.GetHdc();
dc2 = memoryGraphics.GetHdc();
BitBlt(dc2, 0, 0, panel1.ClientRectangle.Width, panel1.ClientRectangle.Height, dc1, 0, 0, 13369376);
mygraphics.ReleaseHdc(dc1);
memoryGraphics.ReleaseHdc(dc2);
}

private void button3_Click(object sender, EventArgs e)
{
printDocument1.Print();
}


//button2事件是区域生成图片,button3是打印区域
------解决方案--------------------
http://www.cnblogs.com/dsf518/archive/2006/09/08/498579.html