Results 1 to 6 of 6

Thread: Why doesn't this code capture all of the my form ?

  1. #1

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,423

    Why doesn't this code capture all of the my form ?

    Hi,
    I'm trying to capture the whole of my Form3.
    Form3 is the only visible form, Form3.Topmost is set to True.
    The image (img) I get is only about 70% of the form.
    I doubt if it's relevent... but just in case... Form3 has no borders.
    Code:
        Private Sub TicketID()
            Dim FrmGph As Graphics = Form3.CreateGraphics()
            Dim img As Bitmap
            Dim fpt As Point = Form3.PointToScreen(New Point(0, 0))
            Dim sz As Size	'  *
    
            sz.Width = Form3.Width
            sz.Height = Form3.Height
            img = New Bitmap(sz.Width, sz.Height, FrmGph)
            Dim tktGph As Graphics = Graphics.FromImage(img)
            tktGph.CopyFromScreen(fpt.X, fpt.Y, 0, 0, sz) ' *  This needs a Size attribute.
        End Sub
    Microsoft Visual Studio Community 2017 Version 15.9.4
    VisualStudio.15 Release/15.9.4+28307.222
    Microsoft .NET Framework Version 4.7.03056
    Windows 10.


    Poppa.
    Along with the sunshine there has to be a little rain sometime.

  2. #2
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,807

    Re: Why doesn't this code capture all of the my form ?

    Quote Originally Posted by Poppa Mintin View Post
    Hi,
    I'm trying to capture the whole of my Form3.
    Form3 is the only visible form, Form3.Topmost is set to True.
    The image (img) I get is only about 70% of the form.
    I doubt if it's relevent... but just in case... Form3 has no borders.
    Code:
        Private Sub TicketID()
            Dim FrmGph As Graphics = Form3.CreateGraphics()
            Dim img As Bitmap
            Dim fpt As Point = Form3.PointToScreen(New Point(0, 0))
            Dim sz As Size	'  *
    
            sz.Width = Form3.Width
            sz.Height = Form3.Height
            img = New Bitmap(sz.Width, sz.Height, FrmGph)
            Dim tktGph As Graphics = Graphics.FromImage(img)
            tktGph.CopyFromScreen(fpt.X, fpt.Y, 0, 0, sz) ' *  This needs a Size attribute.
        End Sub
    Microsoft Visual Studio Community 2017 Version 15.9.4
    VisualStudio.15 Release/15.9.4+28307.222
    Microsoft .NET Framework Version 4.7.03056
    Windows 10.


    Poppa.
    Google is your friend:
    http://www.vbforums.com/showthread.p...ve-Window-Area

  3. #3
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: Why doesn't this code capture all of the my form ?

    I suspect that you have the display set to 125%.
    So, your form may be 300x300 in size, for instance, but on the screen is zoomed to 400x400 pixels because of the 125% setting.
    When you copy from the screen, the function uses the physical pixel size, i.e. 300x300 not the zoomed size, 400x400 so you end up getting 75% of your form.

    There was a thread recently, I believe, that discussed that situation. Unfortunately, its late and I don't feel like trying to find it.

  4. #4
    Hyperactive Member
    Join Date
    Jun 2018
    Posts
    434

    Re: Why doesn't this code capture all of the my form ?

    If all you want is to capture the form then DrawToBitmap the easiest way. It cancels out problems with high resolution monitor settings and control panel text scaling, screen/form coords, etc.

    Another option that can help make your application dpi aware is with settings in the app.config and other areas. But thats more difficult etc.

    How to approach the problem depends on the application use etc.

    As far as your example I am not sure what you think it does?

    Here is a drawtobitmap example. Try it with different dpi settings. Just add a button and picturebox to a form. Click the button and a reduced size capture image is shown in the picturebox.

    Name:  a.png
Views: 150
Size:  11.7 KB

    Code:
    'capture form using DrawToBitmap
    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
            PictureBox1.BackgroundImageLayout = ImageLayout.Zoom
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    
            'capture the form 
            Dim bmp As New Bitmap(Me.Width, Me.Height)
            Me.DrawToBitmap(bmp, New Rectangle(0, 0, Me.Width, Me.Height))
    
            'dispose the last image
            If PictureBox1.BackgroundImage IsNot Nothing Then
                Using bmp2 As Image = PictureBox1.BackgroundImage
                    PictureBox1.BackgroundImage = Nothing
                End Using
            End If
    
            'show the captured image in the picbox reduced size
            PictureBox1.BackgroundImage = bmp
    
        End Sub
    End Class

  5. #5

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,423

    Re: Why doesn't this code capture all of the my form ?

    Thanks guys... That answers the question.


    Poppa.
    Along with the sunshine there has to be a little rain sometime.

  6. #6

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,423

    Re: Why doesn't this code capture all of the my form ?

    Thanks guys... That answers the question.


    Poppa.
    Along with the sunshine there has to be a little rain sometime.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width