0

I'm creating a function that allow a user to save a WindowsForm as a bitmap picture, But it seems like the saved picture haven't the same size as my initial form depending on the resolution of the screen.

Here is the 2 pictures :

The real windows form :

enter image description here

The picture saved as a bitmap :

enter image description here

I'm using this command to create the bitmap file :

Dim f As New tmp()
Dim createControl = f.GetType().GetMethod("CreateControl", _
                                              BindingFlags.Instance Or BindingFlags.NonPublic)
    createControl.Invoke(f, New Object() {True})

    Dim bm As New Bitmap(f.Width, f.Height)
    f.DrawToBitmap(bm, New Rectangle(0, 0, bm.Width, bm.Height))
    bm.Save(Directory.GetCurrentDirectory + "\temp.bmp")

Note that, I want to preserve the quality of the initial windowsform, that's why, i'm trying to have the biggest form as possible.

Toto NaBendo
  • 290
  • 3
  • 26
  • What is the desired outcome? – laancelot Apr 03 '19 at 12:05
  • The same as the first picture. If you look, you can see that the content of the second picture is cutted compared as the first one... I would like to avoid this problem – Toto NaBendo Apr 03 '19 at 12:07
  • 1
    Make you application DPIAware: [How to configure an app to run correctly on a machine with a high DPI setting (e.g. 150%)?](https://stackoverflow.com/a/13228495/7444103). Or size the Bitmap yourself. `[Control].DrawToBitmap is virtualized`. – Jimi Apr 03 '19 at 12:48
  • Thanks you a lot ! I can't mark this comment as an answer but thanks.. – Toto NaBendo Apr 03 '19 at 13:08

0 Answers0