Results 1 to 22 of 22

Thread: Help with picturebox background images

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2007
    Posts
    27

    Help with picturebox background images

    I am trying to have a image with another image layed on top of it. i made one the background and one the main image. but i need a way to make the background image of the picturebox scale like the image does, instead of tiling.

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

    Re: Help with picturebox background images

    The Image and BackgroundImage properties do not behave the same way. The Image appearance is controlled by the SizeMode property while the BackgroundImage appearance is controlled by the BackgroundImageLayout property. There is some similarity but they are not the same.

    If you cannot get the effect you want with the BackgroundImage property then you can use GDI+ to draw an Image directly onto either the Image property or the PictureBox itself. The first is permanent while the second is not.
    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

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2007
    Posts
    27

    Re: Help with picturebox background images

    i have tried to draw it on with GDI+ but whenever i do that it goes behind the picture in the picturebox.

    And could you provide an example of the backgroundimagelayout property, i havent heard of this before.

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

    Re: Help with picturebox background images

    I've never had any problem when drawing on a PictureBox using GDI+. If you are then we'd need to see what you're actually doing.

    You don't need any examples from me. It's a property of the PictureBox so you set it in the Properties window. As you change its value you'll immediately see its effect in the designer. If you want an explanation of the property or the values it can take then the MSDN library is the place to look.
    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

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Mar 2007
    Posts
    27

    Re: Help with picturebox background images

    its not that i have trouble drawing on them, i can draw but then they immediatly dissapear, if i have it fire on the forms paint command it severely lags the program and the overlay flashes but it stays on top.

    Also i do not see that property thing your talking about.

    thx for your help

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

    Re: Help with picturebox background images

    1. What version are you using? BackgroundImageLayout is new in .NET 2.0. If you always specify your version then we shouldn't make invalid assumptions.

    2. If you want to draw on a control you do so on that control's Paint event. If you want to draw on a PictureBox then you do so in the Paint event handler of that PictureBox; not the Paint event handler of the form or anywhere else.
    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

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Mar 2007
    Posts
    27

    Re: Help with picturebox background images

    Im sorry but i am a gigantic noob, how would i check the version.

    And thanks for the advice ill try it.

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

    Re: Help with picturebox background images

    Quote Originally Posted by Just_Another_noob
    Im sorry but i am a gigantic noob, how would i check the version.
    The same way you get information about any application: Help -> About.
    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

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Mar 2007
    Posts
    27

    Re: Help with picturebox background images

    im running 1.1, so i guess i should probably upgrade. How would one go about doing this?

    Also when i put the draw thing on the image boxes paint handle it shows up even less.

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

    Re: Help with picturebox background images

    You are using VS.NET 2003, which targets .NET 1.1 by default. You don't necessarily have to upgrade, but VS 2005 and .NET 2.0 do have more features. VB Express 2005 is a VB-only version of VS 2005 with fewer features and it costs nothing. It supports all features of VB 2005 and .NET 2.0 but the IDE itself has fewer features. If you don't need those lacking features, which its target audience of students and hobbyists don't really, then VB Express is a great product. By all means give it a go and see what you think. If you find you do need the extra features then you can always buy VS Standard or Pro later.

    Drawing on a PictureBox works. If it's not working for you then you're doing it wrong. If you don't show us what you're doing then we can't see what the issue might be.
    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

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Mar 2007
    Posts
    27

    Re: Help with picturebox background images

    Code:
    Private Sub GS1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Menu_Slot_1.Paint
    
            ol = Me.overlay.Image
            ol.MakeTransparent(Color.White)
    
            Me.Menu_Slot_1.CreateGraphics.DrawImage(ol, 0, 0, Menu_Slot_1.Width, Menu_Slot_1.Height)
        End Sub
    as you can see im trying to lay an overlay on top of a picturebox with an image in it.

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

    Re: Help with picturebox background images

    Firstly you're creating a Graphics object and not disposing it, which is a big no-no. Secondly you shouldn't be creating a Graphics object at all. One is already provided for the purpose in the e.Graphics property.
    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

  13. #13

    Thread Starter
    Junior Member
    Join Date
    Mar 2007
    Posts
    27

    Re: Help with picturebox background images

    ok thank you, how should i go about this without creating a surface?

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

    Re: Help with picturebox background images

    As I said in my previous post, a Graphics object is already provided for you in the Paint event handler via the e.Graphics property. The object itself creates the Graphics object, uses it to draw itself, passes it to the event handler(s) so if there are multiple handlers they all use the same one, then destroys the object once it's done.
    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

  15. #15

    Thread Starter
    Junior Member
    Join Date
    Mar 2007
    Posts
    27

    Re: Help with picturebox background images

    OMG dude, i have to thank you sooo much, no wonder it was sooo laggy. That works like a charm.

    You sir, are one smart person

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

    Re: Help with picturebox background images

    Don't mistake experience for intelligence.
    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

  17. #17

    Thread Starter
    Junior Member
    Join Date
    Mar 2007
    Posts
    27

    Re: Help with picturebox background images

    now im having another problem, i am trying to have a hover effect.

    heres my code:

    Code:
        Dim ol As Bitmap
        Dim pcb As PictureBox
    
        Private Sub GS1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Menu_Slot_1.Paint
    
            ol = pcb.Image
            ol.MakeTransparent(Color.White)
    
            e.Graphics.DrawImage(ol, 0, 0, Menu_Slot_1.Width + 1, Menu_Slot_1.Height + 1)
    
        End Sub
    
        Private Sub Menu_Slot_1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Menu_Slot_1.MouseEnter
            pcb = Me.overlay_2
        End Sub
        Private Sub Menu_Slot_1_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Menu_Slot_1.MouseLeave
            pcb = Me.overlay
        End Sub
    It works a few times then stops working, im guessing im not disposing something or having it load too many times. Some insight would be appreciated.

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

    Re: Help with picturebox background images

    Call the Refresh method of the PictureBox you want to change the appearance of in order to force it to repaint. That means in your MouseEnter and MouseLeave event handlers.
    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

  19. #19

    Thread Starter
    Junior Member
    Join Date
    Mar 2007
    Posts
    27

    Re: Help with picturebox background images

    thanks again for your help, but i just got visual studio express which makes everything sooooo much easier.

  20. #20

    Thread Starter
    Junior Member
    Join Date
    Mar 2007
    Posts
    27

    Re: Help with picturebox background images

    Ummmmm, i need some more help.

    I have the new VB.NET but whenever i set the background image and image the background image sticks out like one pixel farther than the image. When i was drawing with GDI+ i fixed this by drawing it with picturebox.width +1.

    Is there anyway to do this in net 2.0 without GDI+?

  21. #21

    Thread Starter
    Junior Member
    Join Date
    Mar 2007
    Posts
    27

    Re: Help with picturebox background images

    No one?

    Sorry for being imaptient. (and triple posting )

  22. #22

    Thread Starter
    Junior Member
    Join Date
    Mar 2007
    Posts
    27

    Re: Help with picturebox background images

    bump

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