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. Windows Forms
  4. How to capture snap of any SDI windowForm including title bar

How to capture snap of any SDI windowForm including title bar

Scheduled Pinned Locked Moved Windows Forms
graphicshelptutorialcomdata-structures
4 Posts 2 Posters 3 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.
  • T Offline
    T Offline
    Tridip Bhattacharjee
    wrote on last edited by
    #1

    below is my routine which works fine but the routine is not generating the image of sdi form with proper height & width. here is my routine and i think there is flaw but i am not being able to capture & fix the flaw. so here is my code. please have a look and guide me what i need to change in this code to fix this flaw.

    protected virtual void OnMinimize(EventArgs e)
    {
    Rectangle r = this.RectangleToScreen(this.ClientRectangle);
    int titleHeight = r.Top - this.Top;

    \_lastSnapshot = new Bitmap(r.Width, r.Height);
    
    using (Image windowImage = new Bitmap(r.Width, r.Height + titleHeight))
    using (Graphics windowGraphics = Graphics.FromImage(windowImage))
    using (Graphics tipGraphics = Graphics.FromImage(\_lastSnapshot))
    {
        windowGraphics.CopyFromScreen(new Point(r.Left, r.Top - titleHeight),
                 new Point(0, 0), new Size(r.Width, r.Height + titleHeight));
        windowGraphics.Flush();
    
        tipGraphics.DrawImage(windowImage, 0, 0, r.Width, r.Height + titleHeight);
        \_lastSnapshot.Save(@".\\tmp.bmp", ImageFormat.Bmp);
    }
    

    }

    with the help of above routine i could generate form image and just click on the link to check. http://i.stack.imgur.com/wCvUl.png[^]

    tbhattacharjee

    L 1 Reply Last reply
    0
    • T Tridip Bhattacharjee

      below is my routine which works fine but the routine is not generating the image of sdi form with proper height & width. here is my routine and i think there is flaw but i am not being able to capture & fix the flaw. so here is my code. please have a look and guide me what i need to change in this code to fix this flaw.

      protected virtual void OnMinimize(EventArgs e)
      {
      Rectangle r = this.RectangleToScreen(this.ClientRectangle);
      int titleHeight = r.Top - this.Top;

      \_lastSnapshot = new Bitmap(r.Width, r.Height);
      
      using (Image windowImage = new Bitmap(r.Width, r.Height + titleHeight))
      using (Graphics windowGraphics = Graphics.FromImage(windowImage))
      using (Graphics tipGraphics = Graphics.FromImage(\_lastSnapshot))
      {
          windowGraphics.CopyFromScreen(new Point(r.Left, r.Top - titleHeight),
                   new Point(0, 0), new Size(r.Width, r.Height + titleHeight));
          windowGraphics.Flush();
      
          tipGraphics.DrawImage(windowImage, 0, 0, r.Width, r.Height + titleHeight);
          \_lastSnapshot.Save(@".\\tmp.bmp", ImageFormat.Bmp);
      }
      

      }

      with the help of above routine i could generate form image and just click on the link to check. http://i.stack.imgur.com/wCvUl.png[^]

      tbhattacharjee

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Unfortunately the ClientRectangle does not include the form borders so that is not useful for capturing the complete window. However the actual location and size is kept in the form's properties and can be used to capture the window as below. And in this case, the title bar size is not needed.

      Rectangle r = new Rectangle(this.Left, this.Top, this.Width, this.Height);

      Bitmap _lastSnapshot = new Bitmap(r.Width, r.Height);

      using (Image windowImage = new Bitmap(r.Width, r.Height))
      using (Graphics windowGraphics = Graphics.FromImage(windowImage))
      using (Graphics tipGraphics = Graphics.FromImage(_lastSnapshot))
      {
      windowGraphics.CopyFromScreen(new Point(r.Left, r.Top), new Point(0, 0), new Size(r.Width, r.Height));
      windowGraphics.Flush();

      tipGraphics.DrawImage(windowImage, 0, 0, r.Width, r.Height);
      \_lastSnapshot.Save(@".\\tmp.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
      

      }

      Use the best guess

      T 1 Reply Last reply
      0
      • L Lost User

        Unfortunately the ClientRectangle does not include the form borders so that is not useful for capturing the complete window. However the actual location and size is kept in the form's properties and can be used to capture the window as below. And in this case, the title bar size is not needed.

        Rectangle r = new Rectangle(this.Left, this.Top, this.Width, this.Height);

        Bitmap _lastSnapshot = new Bitmap(r.Width, r.Height);

        using (Image windowImage = new Bitmap(r.Width, r.Height))
        using (Graphics windowGraphics = Graphics.FromImage(windowImage))
        using (Graphics tipGraphics = Graphics.FromImage(_lastSnapshot))
        {
        windowGraphics.CopyFromScreen(new Point(r.Left, r.Top), new Point(0, 0), new Size(r.Width, r.Height));
        windowGraphics.Flush();

        tipGraphics.DrawImage(windowImage, 0, 0, r.Width, r.Height);
        \_lastSnapshot.Save(@".\\tmp.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
        

        }

        Use the best guess

        T Offline
        T Offline
        Tridip Bhattacharjee
        wrote on last edited by
        #3

        thanks for your answer. i got another trick that is bit small and works well

        Bitmap bmp = new Bitmap(this.Width, this.Height);
        this.DrawToBitmap(bmp, new Rectangle(Point.Empty, bmp.Size));
        bmp.Save(@"d:\Zapps.bmp", ImageFormat.Bmp);

        tbhattacharjee

        L 1 Reply Last reply
        0
        • T Tridip Bhattacharjee

          thanks for your answer. i got another trick that is bit small and works well

          Bitmap bmp = new Bitmap(this.Width, this.Height);
          this.DrawToBitmap(bmp, new Rectangle(Point.Empty, bmp.Size));
          bmp.Save(@"d:\Zapps.bmp", ImageFormat.Bmp);

          tbhattacharjee

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Good catch.

          Use the best guess

          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