Results 1 to 5 of 5

Thread: [RESOLVED] Pass PictureBox to a Function to return modified PictureBox

Hybrid View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Posts
    95

    Resolved [RESOLVED] Pass PictureBox to a Function to return modified PictureBox

    I can't find a solution to my problem.

    Trying to use a function. I want to pass a PictureBox control to this function. I want this funciton to modify the PictureBox's graphics (Lines, Boxes, Circles, etc.) and then to return the PictureBox back to the form with it's new graphics.

    This is what I thought should work. Any help, or solutions?

    VB Code:
    1. Option Explicit
    2.  
    3. Function Update_Graphics(PicBox As Object) As Object    'Also have tried.. As PictureBox
    4.     PicBox.Cls                                          'This does not draw
    5.     PicBox.Scale (0, 0)-(50, 50)
    6.     PicBox.Line (0, 0)-(50, 50)
    7.    
    8.     Set Update_Graphics = PicBox
    9. End Function
    10.  
    11. Private Sub Command1_Click()
    12.     Dim objGraphics As PictureBox
    13.     Set objGraphics = Picture1
    14.     Set Picture1 = Update_Graphics(objGraphics)
    15.  
    16. '    Picture1.Cls                    ' This draws fine
    17. '    Picture1.Scale (0, 0)-(50, 50)
    18. '    Picture1.Line (0, 0)-(50, 50)
    19. End Sub

    Thanks!

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Pass PictureBox to a Function to return modified PictureBox

    This worked fine for me
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Update_Graphics(PicBox As PictureBox)     'Also have tried.. As PictureBox
    4.     PicBox.Cls                                          'This does not draw
    5.     PicBox.Scale (0, 0)-(50, 50)
    6.     PicBox.Line (0, 0)-(50, 50)
    7. End Sub
    8.  
    9. Private Sub Command1_Click()
    10.     Update_Graphics Picture1
    11. End Sub

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Posts
    95

    Re: Pass PictureBox to a Function to return modified PictureBox

    I can get this to work but this is not what I want. I don't even understand what is going on in this code. I don't think the Set Update_Graphics = PicBox is working.


    VB Code:
    1. Option Explicit
    2.  
    3. Function Update_Graphics(PicBox As Object) As Object    'Also have tried.. As PictureBox
    4.     PicBox.Cls                                          'This draws on Picture2 , Why?
    5.     PicBox.Scale (0, 0)-(50, 50)
    6.     PicBox.Line (0, 0)-(50, 50)
    7.    
    8.     Set Update_Graphics = PicBox
    9. End Function
    10.  
    11. Private Sub Command1_Click()
    12. '    Dim objGraphics As PictureBox
    13. '    Set objGraphics = Picture1
    14.     Set Picture1 = Update_Graphics(Picture2)
    15.  
    16. '    Picture1.Cls                    ' This draws fine
    17. '    Picture1.Scale (0, 0)-(50, 50)
    18. '    Picture1.Line (0, 0)-(50, 50)
    19. End Sub

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Posts
    95

    Re: Pass PictureBox to a Function to return modified PictureBox

    Ok, I see.

    Thanks a bunch!

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

    Re: Pass PictureBox to a Function to return modified PictureBox

    Try this:
    VB Code:
    1. Option Explicit
    2.  
    3. Function Update_Graphics(PicBox As PictureBox)
    4.     PicBox.Cls
    5.     PicBox.Scale (0, 0)-(50, 50)
    6.     PicBox.Line (0, 0)-(50, 50)
    7.    
    8. '    Set Update_Graphics = PicBox
    9. End Function
    10.  
    11. Private Sub Command1_Click()
    12.     Dim objGraphics As PictureBox
    13.     Set objGraphics = Picture1
    14.     Update_Graphics objGraphics
    15. End Sub


    Pradeep


    UUh..
    Sorry Hack, I didn't see that post!
    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...

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