Label auf Picture (Picturebox)

  • VB.NET

Es gibt 2 Antworten in diesem Thema. Der letzte Beitrag () ist von reustli.

    Label auf Picture (Picturebox)

    Hallo Zusammen
    Gibt es eine Möglichkeit Label's auf einem Bild zu vereinen? Aktuell habe ich eine PictureBox mit einem Bild darin, zusätzlich sind ein paar Labels auf der PictureBox platziert. Wenn ich nun die Picturebox als Bild speichere oder in die Zwischenablage kopiere kommt natürlich nur das Bild ohne die Label's.
    Gibt es da eine Lösung, dass die Labels auch mitkommen?
    Sieh Dir mal diesen Thread von @mikeb69: an, das Zauberwort heißt Wasserzeichen.
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    OK, danke für die Antwort, habe es anders gemacht, da ich viele Controls auf der Picturebox habe. Mit einem Screenshot der PictureBox, geht in diesem Fall einfacher.

    VB.NET-Quellcode

    1. Private Function ScreenShotFromControl(ByVal pb As System.Windows.Forms.PictureBox, _
    2. ByVal frm As System.Windows.Forms.Form, _
    3. ByVal ctrl As System.Windows.Forms.Control) _
    4. As System.Drawing.Bitmap
    5. Dim g As Graphics = pictureBox1.CreateGraphics()
    6. Dim hBitmap As Bitmap = Nothing
    7. Try
    8. Dim sz As Size = ctrl.Size
    9. hBitmap = New Bitmap(sz.Width, sz.Height, g)
    10. Dim hGraphics As Graphics = Graphics.FromImage(hBitmap)
    11. pb.Width = sz.Width
    12. pb.Height = sz.Height
    13. hGraphics.CopyFromScreen(frm.Location.X + ctrl.Location.X + 4, _
    14. frm.Location.Y + ctrl.Location.y + (frm.Height - frm.ClientSize.Height - 4), _
    15. 0, 0, sz)
    16. Return hBitmap
    17. Catch
    18. If (Not g Is Nothing) Then g.Dispose()
    19. Finally
    20. If (Not g Is Nothing) Then g.Dispose()
    21. End Try
    22. Return Nothing
    23. End Function