Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Panel screencapture is black in invisible part of panel

Panel screencapture is black in invisible part of panel

Scheduled Pinned Locked Moved C#
graphicshelpquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    joost versteegen
    wrote on last edited by
    #1

    hello tried to make a screencapture of a panel with controls on it and "connections" at the background (created using paint() procedure). DrawToBitmap does only the visible part of the panel, so i came up with the following code after a while. problem is that the invisible part of the panel turns up black in the resulting jpeg picture. Does anyone have any suggestions for me?

    	protected virtual void mnuRptClicked(object sender, EventArgs e)
    	{
    		this.AutoScrollPosition = new Point(0, 0);
    		// get dimensions
    		int w = 0,h = 0;
    		foreach(Control c in this.Controls )
    		{
    			if(c.Left + c.Width > w) w = c.Left + c.Width + 100;
    			if(c.Top  + c.Height  > h) h = c.Top  + c.Height + 100;
    		}
    		if(w == 0) w = this.DisplayRectangle.Width;
    		if(h == 0) h = this.DisplayRectangle.Height;
    		// create bitmap
    		Bitmap b = new Bitmap(w,h);
    		Graphics bg = Graphics.FromImage(b);
    		// copy screen to bitmap
    		// TODO: invisible part of screen turns out black
    		int bgHdc = (int)bg.GetHdc();
    		SendMessage(this.Handle , WM\_PAINT, bgHdc, 0);
    		SendMessage(this.Handle, WM\_PRINT, bgHdc, (int)(
    					DrawingOptions.PRF\_OWNED |
    					DrawingOptions.PRF\_CHILDREN | 
    					DrawingOptions.PRF\_CLIENT)
    					);
    		bg.ReleaseHdc();
    		bg.Dispose ();
    		// save the result as captured.jpeg
    		b.Save(Application.StartupPath + @"\\captured.jpg", ImageFormat.Jpeg);
    		b.Dispose ();
    	}
    
    L 1 Reply Last reply
    0
    • J joost versteegen

      hello tried to make a screencapture of a panel with controls on it and "connections" at the background (created using paint() procedure). DrawToBitmap does only the visible part of the panel, so i came up with the following code after a while. problem is that the invisible part of the panel turns up black in the resulting jpeg picture. Does anyone have any suggestions for me?

      	protected virtual void mnuRptClicked(object sender, EventArgs e)
      	{
      		this.AutoScrollPosition = new Point(0, 0);
      		// get dimensions
      		int w = 0,h = 0;
      		foreach(Control c in this.Controls )
      		{
      			if(c.Left + c.Width > w) w = c.Left + c.Width + 100;
      			if(c.Top  + c.Height  > h) h = c.Top  + c.Height + 100;
      		}
      		if(w == 0) w = this.DisplayRectangle.Width;
      		if(h == 0) h = this.DisplayRectangle.Height;
      		// create bitmap
      		Bitmap b = new Bitmap(w,h);
      		Graphics bg = Graphics.FromImage(b);
      		// copy screen to bitmap
      		// TODO: invisible part of screen turns out black
      		int bgHdc = (int)bg.GetHdc();
      		SendMessage(this.Handle , WM\_PAINT, bgHdc, 0);
      		SendMessage(this.Handle, WM\_PRINT, bgHdc, (int)(
      					DrawingOptions.PRF\_OWNED |
      					DrawingOptions.PRF\_CHILDREN | 
      					DrawingOptions.PRF\_CLIENT)
      					);
      		bg.ReleaseHdc();
      		bg.Dispose ();
      		// save the result as captured.jpeg
      		b.Save(Application.StartupPath + @"\\captured.jpg", ImageFormat.Jpeg);
      		b.Dispose ();
      	}
      
      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      Use PrintWindow instead.

      xacc.ide - now with TabsToSpaces support
      IronScheme - 1.0 alpha 4a out now (29 May 2008)

      J 1 Reply Last reply
      0
      • L leppie

        Use PrintWindow instead.

        xacc.ide - now with TabsToSpaces support
        IronScheme - 1.0 alpha 4a out now (29 May 2008)

        J Offline
        J Offline
        joost versteegen
        wrote on last edited by
        #3

        PrintWindow only gives me the visible part of the panel, and it also gives me the scrollbars !

        L 1 Reply Last reply
        0
        • J joost versteegen

          PrintWindow only gives me the visible part of the panel, and it also gives me the scrollbars !

          L Offline
          L Offline
          leppie
          wrote on last edited by
          #4

          Sorry I didnt realise you were in a scrollable panel, I thought you were trying to print a window behind some other window, or off screen.

          xacc.ide - now with TabsToSpaces support
          IronScheme - 1.0 alpha 4a out now (29 May 2008)

          J 1 Reply Last reply
          0
          • L leppie

            Sorry I didnt realise you were in a scrollable panel, I thought you were trying to print a window behind some other window, or off screen.

            xacc.ide - now with TabsToSpaces support
            IronScheme - 1.0 alpha 4a out now (29 May 2008)

            J Offline
            J Offline
            joost versteegen
            wrote on last edited by
            #5

            anyone else a suggestion?

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups