■No35280に返信(ま〜さんの記事)
> こんにちは、体調を崩して回答が遅れました。すみません。
お大事に。
> ですがTabPage環境化ではズレました。> Parentをと思って色々やってみましたが中々上手くいかずTabPage下の座標知る方法はないのでしょうか?
むむむ、やっかいですね高DPI。
スクリーン座標を取るのが目的でないなら、以下のコードでキャプチャはできると思います。
Imports System.Runtime.InteropServices
Public Class Form1
Public Sub New()
InitializeComponent()
PictureBox1.SizeMode = PictureBoxSizeMode.Zoom
PictureBox1.Size = RichTextBox1.Size
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim bmp = CreateBitmapFromControl(RichTextBox1)
If PictureBox1.Image IsNot Nothing Then
PictureBox1.Image.Dispose()
End If
PictureBox1.Image = bmp
End Sub
Private Const SRCCOPY As Integer = &HCC0020
<DllImport("User32.dll")>
Private Shared Function GetWindowDC(hWnd As IntPtr) As IntPtr
End Function
<DllImport("user32.dll")>
Private Shared Function ReleaseDC(hWnd As IntPtr, hDC As IntPtr) As Boolean
End Function
<DllImport("gdi32.dll")>
Private Shared Function BitBlt(hdcDest As IntPtr,
nXDest As Integer, nYDest As Integer,
nWidth As Integer, nHeight As Integer,
hdcSrc As IntPtr,
nXSrc As Integer, nYSrc As Integer,
dwRop As Integer) As Boolean
End Function
Private Shared Function CreateBitmapFromControl(con As Control) As Bitmap
Dim cs = con.Size
Dim bmp As New Bitmap(cs.Width, cs.Height)
Using g = Graphics.FromImage(bmp)
Dim hdcDest = g.GetHdc()
Dim hdcSrc = GetWindowDC(con.Handle)
BitBlt(hdcDest, 0, 0, cs.Width, cs.Height, hdcSrc, 0, 0, SRCCOPY)
ReleaseDC(con.Handle, hdcSrc)
g.ReleaseHdc()
End Using
Return bmp
End Function
End Class