Results 1 to 9 of 9

Thread: [RESOLVED] PictureBox screenshot

  1. #1

    Thread Starter
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Resolved [RESOLVED] PictureBox screenshot

    I have reached a mind block. This is what I have. A label control inside the picturebox.

    Name:  Sample.png
Views: 1298
Size:  84.5 KB

    I am not able to get label1 screenshot with picturebox1 screenshot. Couple of days ago I did manage that but now it is not working... Not sure what did I change.
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,414

    Re: PictureBox screenshot

    try setting your label's parent property:

    Code:
    Label1.Parent = PictureBox1

  3. #3
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: PictureBox screenshot

    Because you are only drawing the PictureBox. Don't you want to draw the form at the coordinates of the PictureBox?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  4. #4

    Thread Starter
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: PictureBox screenshot

    @Paul: I am aware of that but the problem with that is it will change the co-ordinates of the label and hence I will not get the exact screenshot which I want.
    @dbasnett: Yes we can do that as well. But the same code was working till yesterday. I don't know what did I change
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: PictureBox screenshot

    If you place the Label exactly where you want it on the form, here's how to change it's parent without changing its absolute location:
    Code:
    Private Sub SetParentWithoutMoving(child As Control, newParent As Control)
        child.Location = newParent.PointToClient(child.PointToScreen(Point.Empty))
        child.Parent = newParent
    End Sub
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,414

    Re: PictureBox screenshot

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Label1.Parent IsNot PictureBox1 Then
            Dim position As Point = Label1.Location
            Label1.Parent = PictureBox1
            position.Offset(-PictureBox1.Left, -PictureBox1.Top)
            Label1.Location = position
        End If
        PictureBox1.DrawToBitmap('etc
    End Sub

  7. #7
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: PictureBox screenshot

    The easiest way to resolve your problem without any coding is to simply replace your PictureBox with some container control.
    e.g. Replace your PictureBox with a Panel control and retry whatever you were doing. If you face some difficulty, use the "Document Outline" window to ensure that your child controls (Label in this case), are children of your Panel control.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  8. #8
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: PictureBox screenshot

    Try this code, it is capture the screen region occupied by Picture1
    Code:
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    
            Dim imgBmp As New Bitmap(PictureBox1.Width, PictureBox1.Height)
            Dim gfx As Graphics = Graphics.FromImage(imgBmp)
            Dim sr As Rectangle = RectangleToScreen(PictureBox1.Bounds)
            gfx.CopyFromScreen(sr.Left, sr.Top, 0, 0, imgBmp.Size)
            imgBmp.Save("g:\Sample.bmp", Imaging.ImageFormat.Bmp)
    
            'PictureBox2.Load("g:\Sample.bmp")
    
        End Sub



  9. #9

    Thread Starter
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: PictureBox screenshot

    Quote Originally Posted by Pradeep1210 View Post
    The easiest way to resolve your problem without any coding is ....
    Thank You gents. I liked Pradeep's idea of using a panel instead of picturebox. I just tested it and it suits my need perfectly. Let me explain what I was actually trying to do. I am creating a an App which will let you create VBF flair which you can then use in your blogs and websites. See this Example

    Name:  VBF Flair.png
Views: 450
Size:  44.4 KB

    This was the last piece of the puzzle, Now I can post the App in the Utility Bank.

    @Rest: I will try your codes as well. Thanks.
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

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