■98732 / inTopicNo.21) |
Re[18]: 仮想ディスプレイの座標を取得する方法 |
□投稿者/ くま (83回)-(2021/12/18(Sat) 22:20:32)
|
次々違う質問をされると回答できませんよ。
> Clipboard.SetImage(PictureBox1.Image)
> だと、PictureBox1_Paint上に書いたラインなどが描画されません、
ラインの描写先が間違っていませんか?
Dim objPen = New Pen(System.Drawing.Color.Blue, 2)
Dim objFont = New Font("MS Pゴシック", 15)
Dim objGrp As Graphics = Graphics.FromImage(PictureBox1.Image) 'ここポイント
' 直線を引く
objGrp.DrawLine(objPen, 20, 20, 200, 200)
' 楕円を描く
objGrp.DrawEllipse(objPen, 10, 10, 190, 190)
' 楕円を描く
objGrp.DrawString("描画テスト", objFont, Brushes.Red, 80, 100)
' リソースを解放する
objPen.Dispose()
objFont.Dispose()
objGrp.Dispose()
Clipboard.SetImage(PictureBox1.Image)
これで書かれた線などもクリップボードに読み込まれます。
というかそうしないとフォーム最小化とか重なった後書いた線消えてるでしょ?
フォーム全体なら
'コントロールの外観を描画するBitmapの作成
Dim bmp As New Bitmap(Me.Width, Me.Height)
'キャプチャする
Me.DrawToBitmap(bmp, New Rectangle(0, 0, Me.Width, Me.Height))
Clipboard.SetImage(bmp)
bmp.Dispose()
> あと、Chart1に関してもクリップボードにコピーしたいのですが、
> これにはImageがないのでコピーすることができません。
コントロールだけなら
フォームやコントロールの外観をキャプチャする
https://dobon.net/vb/dotnet/graphics/invokepaint.html
<System.Runtime.InteropServices.DllImport("User32.dll")> _
Private Shared Function PrintWindow(ByVal hwnd As IntPtr, _
ByVal hDC As IntPtr, ByVal nFlags As Integer) As Boolean
End Function
''' <summary>
''' コントロールのイメージを取得する
''' </summary>
''' <param name="ctrl">キャプチャするコントロール</param>
''' <returns>取得できたイメージ</returns>
Public Function CaptureControl(ByVal ctrl As Control) As Bitmap
Dim img As New Bitmap(ctrl.Width, ctrl.Height)
Dim memg As Graphics = Graphics.FromImage(img)
Dim dc As IntPtr = memg.GetHdc()
PrintWindow(ctrl.Handle, dc, 0)
memg.ReleaseHdc(dc)
memg.Dispose()
Return img
End Function
Dim bmp As Bitmap = CaptureControl(Chart1)
Clipboard.SetImage(bmp)
bmp.Dispose()
|
|