-
Dec 31st, 2018, 12:08 PM
#1
Thread Starter
PowerPoster
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.
-
Dec 31st, 2018, 05:04 PM
#2
Re: Why doesn't this code capture all of the my form ?
Originally Posted by Poppa Mintin
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
-
Dec 31st, 2018, 10:36 PM
#3
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.
-
Jan 1st, 2019, 04:13 AM
#4
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.
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
-
Jan 6th, 2019, 07:56 AM
#5
Thread Starter
PowerPoster
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.
-
Jan 6th, 2019, 07:56 AM
#6
Thread Starter
PowerPoster
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|