-1

I Can capture Screenshot with any of the following procedure mentioned in the link

Capture screenshot of active window?

But I want to capture Screenshot by eliminating certain controls in the form.

Example: If I dont want textbox in form then in screenshot It should be marked black.

2 Answers2

1

If the control's parent is the form, you could do something like this:

Rectangle bounds = this.Bounds;
using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
{
    using (Graphics g = Graphics.FromImage(bitmap))
    {
        g.CopyFromScreen(new Point(bounds.Left, bounds.Top), Point.Empty, bounds.Size);
        Rectangle formScreenRect = RectangleToScreen(this.ClientRectangle);
        int offsetX = formScreenRect.Left - this.Left;
        int offsetY = formScreenRect.Top - this.Top;
        Rectangle textBoxRect = new Rectangle(textBox1.Left + offsetX, 
                                              textBox1.Top + offsetY,
                                              textBox1.Width, textBox1.Height);
        g.FillRectangle(Brushes.Black, textBoxRect);
    }
    // Save the image or do whatever you want with it.
    bitmap.Save(@"C:\test.png", ImageFormat.Png);
}

This calculates the location of the TextBox relative to the form size (not client size) and then uses FillRectangle() to cover it with a rectangle with a color of your choice.

Output:

Form

0

@Ahmed Abdelhameed has already answered your question but if you do not want the black box to be appeared to make it look even better you can just do the following Using the answer on The post you tagged

You can simply do the following:

textbox1.visible = false;

// Code to take the snapshot and save it

textbox1.visible = true;
Amir
  • 721
  • 6
  • 21
  • I want to capture this by library without any effect on the form. But Thanks for answer –  Jul 27 '18 at 03:38
  • It would not create any effect on form since you are making the controls invisible and after you have taken the picure you are making them visible again if you see the code again. – Amir Jul 27 '18 at 09:43