如题
如FrmTEST:UCForm,FrmTEST上有按钮Botton1,点击后实现CopyFromScreen ,此时所得图片无FrmTEST显示
如FrmTEST:Form,FrmTEST上有按钮Botton1,点击后实现CopyFromScreen ,此时所得图片有FrmTEST显示
问原因,求解决办法

解决方案 »

  1.   


            protected override void OnPaint(PaintEventArgs e)
            {
                Bitmap bitmap = PrintScreen();
                e.Graphics.DrawImage(bitmap, this.ClientRectangle, this.PointToScreen(new Point(0, 0)).X, this.PointToScreen(new Point(0, 0)).Y,this.Width,this.Height,GraphicsUnit.Pixel);
                bitmap.Save("dfdsfsf.bmp")
    }class POPO : UserControl1<--这时得到的dfdsfsf.bmp相当于是POPO的visible是false的效果

    class POPO : Form<--这时得到的dfdsfsf.bmp相当于是POPO的visible是true的效果
    但其实POPO 一直都是可见的
    UserControl1里自己重写了Onpaint
      

  2.   


    private Bitmap PrintScreen()
            {
                Bitmap bitmap = null;
                int hsdc, hmdc;
                int hbmp, hbmpold;
                int fw, fh;
                int r;            hsdc = Timms.Net.Tdcs.TControls.WIN32API.WIN32.CreateDC("DISPLAY", "", "", "");
                hmdc = (int)Timms.Net.Tdcs.TControls.WIN32API.WIN32.CreateCompatibleDC((IntPtr)hsdc);            fw = Timms.Net.Tdcs.TControls.WIN32API.WIN32.GetDeviceCaps(hsdc, 8);
                fh = Timms.Net.Tdcs.TControls.WIN32API.WIN32.GetDeviceCaps(hsdc, 10);            hbmp = Timms.Net.Tdcs.TControls.WIN32API.WIN32.CreateCompatibleBitmap(hsdc, fw, fh);            hbmpold = Timms.Net.Tdcs.TControls.WIN32API.WIN32.SelectObject(hmdc, hbmp);
                r = Timms.Net.Tdcs.TControls.WIN32API.WIN32.BitBlt(hmdc, 0, 0, fw, fh, hsdc, 0, 0, 13369376);
                hbmp = Timms.Net.Tdcs.TControls.WIN32API.WIN32.SelectObject(hmdc, hbmpold);            Timms.Net.Tdcs.TControls.WIN32API.WIN32.DeleteDC((IntPtr)hsdc);
                Timms.Net.Tdcs.TControls.WIN32API.WIN32.DeleteDC((IntPtr)hmdc);            bitmap = Image.FromHbitmap((IntPtr)hbmp);
                Timms.Net.Tdcs.TControls.WIN32API.WIN32.DeleteObject((IntPtr)hbmp);
                return bitmap;
            }以上代码其实和CopyFromScreen一样
    Bitmap bitmap = PrintScreen();
    替换为Bitmap bitmap = new Bitmap(this.Width,this.Height);
    e.Graphics.CopyFromScreen(....)其结果也是一样的
      

  3.   

    汗....问题的原因是我重写了Form的OnPaint,然后我继承这个Form的窗体按钮中调用CopyFromScreen中得到的图片(其中这个继承的窗体部分)是透明的
      

  4.   

    用键盘printScreen是没有问题的(其中这个继承的窗体部分是可见的的),为什么CopyFromScreen就会得到透明的?怎么解决这个问题呢?