0

I am trying to use Form.DrawToBitmap to get an image of the current form. It works fine but shows the window border. How could I get it to create a bitmap of the form without the border.

Note: I'm aware that changing the form border style to "None" would work but switching the form border style twice (to "None" and back) at runtime is not really something I want every end-user to be seeing every time this function procs.

Jtoomer
  • 11
  • 1

1 Answers1

1

First use DrawToBitmap method and then crop the image by cloning it and give your desire rectangle somthing like:

    private Bitmap ConvertToImage()
    {
        using (var bitmap = new Bitmap(this.Width, this.Height))
        {
            this.DrawToBitmap(bitmap, this.Bounds);
            return bitmap.Clone(new Rectangle(DESIRE_X, DESIRE_Y, DESIRE_WIDTH, DESIRE_HEIGHT), bitmap.PixelFormat);
        }
    }
Hesam Faridmehr
  • 1,176
  • 8
  • 20