Results 1 to 19 of 19

Thread: [RESOLVED] [2005] Background image in MDIForm

  1. #1

    Thread Starter
    Addicted Member Genom's Avatar
    Join Date
    May 2006
    Posts
    186

    Resolved [RESOLVED] [2005] Background image in MDIForm

    Hi,

    I know this seems to be a simple question but however (I am really surprised) I cant find any solution for this problem.

    The problem is:

    I want to put a background picture to my MDI form. Image has to be taken in runtime from an image file. Like everybody I tried to put it as backgroundimage.
    Code:
    Me.BackgroundImage = Image.FromFile(My.Settings.Logo)
    If I do it like this and whenever I move scrolls of child forms image looks bad. (Because of paint issues) You can understand it if you try or I can put screenshot if you want.

    So I tried to put a picturebox. I wrote a code s that it is being centered etc...

    Now the problem is that picurebox comes in front of the child forms. So I put PictureBox1.sendtoback() and then picture box disappeared! It really interesting that I cant put a background image

    (I mean dark gray region in MDI form)

    Do you know any solution?
    Dim Me As Coder

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

    Re: [2005] Background image in MDIForm

    use child forms bringtofront

  3. #3

    Thread Starter
    Addicted Member Genom's Avatar
    Join Date
    May 2006
    Posts
    186

    Re: [2005] Background image in MDIForm

    Code is for childforms:
    Code:
                frmStok.MdiParent = Me
                frmStok.Show()
                frmStok.BringToFront()
    It should work?
    Dim Me As Coder

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

    Re: [2005] Background image in MDIForm

    If you are not aware of the MdiClient class then nothing you do will work. Follow the MDI Background link in my signature for the solution.
    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
    Addicted Member Genom's Avatar
    Join Date
    May 2006
    Posts
    186

    Re: [2005] Background image in MDIForm

    It doenst work. It is as same as "Me.BackgroundImage". If I move a childform on the picture it is being cut and bad I will put a screenshot...


    Image with the text "Logo Alanı" is normally not like that.
    It happens with your and my code. It only doesnt happen if I put the image in a picturebox but then picturebox stands in front of the forms.
    Last edited by Genom; Jan 29th, 2008 at 08:05 PM.
    Dim Me As Coder

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

    Re: [2005] Background image in MDIForm

    Odd that it works perfectly for me. Post your EXACT code.
    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
    Addicted Member Genom's Avatar
    Join Date
    May 2006
    Posts
    186

    Re: [2005] Background image in MDIForm

    have you tried move form "out" the form and let scrollbars appear and move them?

    Maybe it is because of my splitcontainer...
    Dim Me As Coder

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

    Re: [2005] Background image in MDIForm

    Start with a brand new project and try it. Does it work? If not then what is different about the new project compared to the original? Make changes one by one to the new project to make it resemble the original. When the new project breaks you've found your issue. That's called software development.
    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
    Addicted Member Genom's Avatar
    Join Date
    May 2006
    Posts
    186

    Re: [2005] Background image in MDIForm

    The problem is that it happens in an empty project too. And I cant find any solution for that. If it happens in an empty project too with a simple MDI form I cant find the differences which cause this problem. And it amazing that .net developers dont know this...?
    Dim Me As Coder

  10. #10

    Thread Starter
    Addicted Member Genom's Avatar
    Join Date
    May 2006
    Posts
    186

    Re: [2005] Background image in MDIForm

    These are screenshots of the problem:



    Dim Me As Coder

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

    Re: [2005] Background image in MDIForm

    I think I see what you're saying now. If you scroll the parent form the background doesn't get redrawn properly. I didn't register the scrolling bit before. That does present some problems as there doesn't immediately appear to be an appropriate event to use to refresh the background. I'll look into it.
    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

  12. #12

    Thread Starter
    Addicted Member Genom's Avatar
    Join Date
    May 2006
    Posts
    186

    Re: [2005] Background image in MDIForm

    thanks ... and sorry for my bad explanation and english...
    Dim Me As Coder

  13. #13
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [2005] Background image in MDIForm

    This probably won't be simple to accomplish. Unfortunatly the MDIClient class is not easy to work with because it can't be inherited to add custom functionality, and it also doesn't inherit from scrollable control (even though it is a scrollable control) so you don't get a scroll event. It does fire sizing events when scrollbars are changed from visible to invisible (from dragging child form) because the scrollbars change the available client size of the control, however no events fire if you scroll the scrollbars by clicking the arrows up and down, so you still get tearing of the image.

  14. #14

    Thread Starter
    Addicted Member Genom's Avatar
    Join Date
    May 2006
    Posts
    186

    Re: [2005] Background image in MDIForm

    Because of this I changed my code and put a picturebox but this time it comes in front of the forms and if I send back it disappears... Can you give me an idea about this issue?
    Dim Me As Coder

  15. #15

    Thread Starter
    Addicted Member Genom's Avatar
    Join Date
    May 2006
    Posts
    186

    Re: [2005] Background image in MDIForm

    For who cares it I have finally found a solution...

    vb Code:
    1. Private Sub frmStok_Move(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Move
    2.         Dim MDI As frmMDI = Me.MdiParent
    3.  
    4.         MDI.LogoKoy(1) 'puts the picture
    5.  
    6.     End Sub

    frmStok is a childform. the parameter "1" tells that picture has been taken and only refreshs it... (Me.BackgroundImage = Image.FromFile(Path))

    It works but it has a bad effect on performance.
    Dim Me As Coder

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

    Re: [2005] Background image in MDIForm

    Quote Originally Posted by Genom
    Because of this I changed my code and put a picturebox but this time it comes in front of the forms and if I send back it disappears... Can you give me an idea about this issue?
    Think about it for a bit. The form contains an MdiClient control. The MdiClient control contains the child forms. If you put any other control, like a PictureBox, on top of the MdiClient then of course it's going to be on top of anything the MdiClient contains too.

    It really comes down to the fact that you're not intended to do this sort of thing so no easy way has been provided. If you were supposed to then the MdiClient control wouldn't be hidden in the first place.

    What you could do is try drawing the Image using GDI+ instead of using the BackgroundImage property. I've got a feeling that this would not work either though, because the issue already encountered suggests that the MdiClient is not repainted when it's scrolled. Might be worth a look though.
    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
    Addicted Member Genom's Avatar
    Join Date
    May 2006
    Posts
    186

    Re: [RESOLVED] [2005] Background image in MDIForm

    yes the event is missing too. However it is "resolved" and thank you a lot!!!
    Dim Me As Coder

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

    Re: [RESOLVED] [2005] Background image in MDIForm

    One final idea. You could subclass the MdiClient with a NativeWindow, which doesn't require you to actually inherit the MdiClient class. You would then intercept the appropriate Windows messages and you could then force the MdiClient to repaint at the appropriate times.

    I've messed with subclassing in VB a bit but I'm far from an expert. If you want to investigate this route then I suggest that you look up the NativeWindow class and subclassing on MSDN.
    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
    Addicted Member Genom's Avatar
    Join Date
    May 2006
    Posts
    186

    Re: [RESOLVED] [2005] Background image in MDIForm

    I think performance wont be better than repainting it every childform move... But I will keep in mind it will be very useful for my projects...
    Dim Me As Coder

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