C# 打印窗体,如何做到真正打印form内容 5
C#打印窗体我在打印时主要用到了publicBitmapPrintScreen(Formfm){try{Graphicsmygraphics=fm.CreateGraph...
C# 打印窗体
我在打印时主要用到了
public Bitmap PrintScreen(Form fm)
{
try
{
Graphics mygraphics = fm.CreateGraphics();
Size s = fm.Size;
memoryImage = new Bitmap(s.Width, s.Height, mygraphics);
Graphics memoryGraphics = Graphics.FromImage(memoryImage);
IntPtr dc1 = mygraphics.GetHdc();
IntPtr dc2 = memoryGraphics.GetHdc();
BitBlt(dc2, 0, 0, s.Width, s.Height, dc1, 0, 0, 13369376);
mygraphics.ReleaseHdc(dc1);
memoryGraphics.ReleaseHdc(dc2);
return memoryImage;
}
catch (Exception ex)
{
//more
return memoryImage;
}
}
正常情况下如果要打印的form窗体是在最前端的话是没问题的,但当该窗体上面有别的东西,比如说打开个平时的播放器并将该播放器置顶,则在打印窗体时,该播放器的画面将会比打印。而我想要的是不管窗体被什么覆盖了,我都希望打出来的是form里面的内容。 展开
我在打印时主要用到了
public Bitmap PrintScreen(Form fm)
{
try
{
Graphics mygraphics = fm.CreateGraphics();
Size s = fm.Size;
memoryImage = new Bitmap(s.Width, s.Height, mygraphics);
Graphics memoryGraphics = Graphics.FromImage(memoryImage);
IntPtr dc1 = mygraphics.GetHdc();
IntPtr dc2 = memoryGraphics.GetHdc();
BitBlt(dc2, 0, 0, s.Width, s.Height, dc1, 0, 0, 13369376);
mygraphics.ReleaseHdc(dc1);
memoryGraphics.ReleaseHdc(dc2);
return memoryImage;
}
catch (Exception ex)
{
//more
return memoryImage;
}
}
正常情况下如果要打印的form窗体是在最前端的话是没问题的,但当该窗体上面有别的东西,比如说打开个平时的播放器并将该播放器置顶,则在打印窗体时,该播放器的画面将会比打印。而我想要的是不管窗体被什么覆盖了,我都希望打出来的是form里面的内容。 展开
展开全部
try
{
bool fmTopMost = fm.TopMost;
int s_wid = Screen.PrimaryScreen.Bounds.Width;
int s_height = Screen.PrimaryScreen.Bounds.Height;
Size fs = fm.Size;
Bitmap b_1 = new Bitmap(fs.Width,fs.Height);
Graphics mygraphics = Graphics.FromImage(b_1);
mygraphics.CopyFromScreen(fm.Location.X, fm.Location.Y, 0, 0, fs);
b_1.Save(@"C:\Users\用户名\Desktop\test" + DateTime.Now.ToString("yyyyMMddhhmmssmm") + ".bmp", System.Drawing.Imaging.ImageFormat.Bmp);
fm.TopMost = fmTopMost;
}
catch (Exception ex)
{
//more
MessageBox.Show(ex.Message);
}
{
bool fmTopMost = fm.TopMost;
int s_wid = Screen.PrimaryScreen.Bounds.Width;
int s_height = Screen.PrimaryScreen.Bounds.Height;
Size fs = fm.Size;
Bitmap b_1 = new Bitmap(fs.Width,fs.Height);
Graphics mygraphics = Graphics.FromImage(b_1);
mygraphics.CopyFromScreen(fm.Location.X, fm.Location.Y, 0, 0, fs);
b_1.Save(@"C:\Users\用户名\Desktop\test" + DateTime.Now.ToString("yyyyMMddhhmmssmm") + ".bmp", System.Drawing.Imaging.ImageFormat.Bmp);
fm.TopMost = fmTopMost;
}
catch (Exception ex)
{
//more
MessageBox.Show(ex.Message);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询