Results 1 to 35 of 35

Thread: MDI Background Image

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2005
    Posts
    48

    MDI Background Image

    Hey,

    I want to add a background image to an MDI parent but I'm running into some troubles. I want to have the picture to always stay in the center.

    Originally I tried to add the picture to the forms background image but it tiles the image and the white background causes weird stuff to happen even though I adjusted the Transparency property.

    Then I tried to use a picturebox which I could resize accordingly to the window and it looked great... however, whenever I open a child form in the MDI, it doesn't appear because I'm pretty sure its behind the picturebox. I tried to fix this using the SendToBack and BringToFront methods but it didn't work.

    Any suggestions?

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

    Re: MDI Background Image

    what version of visual studio are you using?

    and howcome people aren't using the new radio buttons to automatically add the .NET version to the thread subject?? It makes it easier for both the poster and the people providing help...

  3. #3

    Thread Starter
    Member
    Join Date
    Dec 2005
    Posts
    48

    Re: MDI Background Image

    VS 2003

    Didn't see any new radio buttons anywhere...

  4. #4
    Hyperactive Member OMITT3D's Avatar
    Join Date
    Mar 2006
    Posts
    368

    Re: MDI Background Image

    and howcome people aren't using the new radio buttons to automatically add the .NET version to the thread subject?? It makes it easier for both the poster and the people providing help...
    Nobody can see them unless they are pointed out. Least for me that was the case.

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

    Re: MDI Background Image

    when you create a new thead, there are radio buttons to ask what version of VS you are using.. just helps to get you an answer faster.. you dont want someone giving you a solution that works only in 2005, if you are using 2003, and vice versa...

    anyway as far as your issue, perhaps you can use GDI+ to draw the image.. i will see if I can do you up an example

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

    Re: MDI Background Image

    ok, here is the example.

    the only limitations are that you will get flickering when dragging the size grip (lower right corner) to resize the form.. there is really nothing you can do about that.. flicker has always been a problem in windows forms)

    That is not to say it can't be fixed, but it would be more complex, probably using double buffering of some sort. I am not a super expert on GDI+, so I am not sure exactly how you would implement it.

    Other than that, it does what you wanted... centers the image on the MDI parent, and mdi children work fine...
    Attached Files Attached Files

  7. #7
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040

    Re: MDI Background Image

    Nobody can see them unless they are pointed out. Least for me that was the case.

    Agreeeeeeeeeed, i didn't see the radio buttons until today when i read your post

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

    Re: MDI Background Image

    Quote Originally Posted by OMITT3D
    Nobody can see them unless they are pointed out. Least for me that was the case.
    What's with people? They are about half a centimetre from where you type in the thread title.
    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
    Fanatic Member
    Join Date
    Sep 2007
    Posts
    839

    Re: MDI Background Image

    to kleinma,
    Hi, based on you example in POST#6 there only on picture, i want many picture to be shown... and changing for every 10 seconds... and i had 20 pictures to be shown...

    how to do this..?

  10. #10
    Fanatic Member
    Join Date
    Sep 2007
    Posts
    839

    Re: MDI Background Image

    by the way i'm using VB .net 2005..

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

    Re: MDI Background Image

    Quote Originally Posted by edgarbenilde
    to kleinma,
    Hi, based on you example in POST#6 there only on picture, i want many picture to be shown... and changing for every 10 seconds... and i had 20 pictures to be shown...

    how to do this..?
    use a timer control, set it's interval to 10000 (10 seconds) and in the timers tick/elapsed event put code that changes what pictures will be shown when the MDI parent draws its background, then call the forms .invalidate() method to force a repaint.

  12. #12
    Fanatic Member
    Join Date
    Sep 2007
    Posts
    839

    Re: MDI Background Image

    How, i don't know how to set it..?

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

    Re: MDI Background Image

    Quote Originally Posted by edgarbenilde
    How, i don't know how to set it..?
    You set it in exactly the same way as you set any other property. If we said "set the Text property of a TextBox" I'm guessing you could do it. Setting the Interval property of a Timer is exactly the same.
    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

  14. #14
    Addicted Member
    Join Date
    Apr 2006
    Posts
    137

    Re: MDI Background Image

    timer1.interval = 10000
    Jesse Bunch
    www.getbunch.com/
    If I have helped you, please rate my posts!

    Unless otherwise indicated, I am using the following Products:

    Visual Studio .NET 2010
    .NET Framework 4.0

  15. #15
    Fanatic Member
    Join Date
    Sep 2007
    Posts
    839

    Re: MDI Background Image

    i really don't know please help..

    here is the in getting the picture.. i
    m wanting more picture to display.. where do i put the other code for more images..?

    here is the codes..

    'GET THE IMAGE (IT IS COMPILED WITHIN THE EXE AS AN EMBEDDED RESOURCE)
    Dim MyImage As Image = Image.FromStream(Me.GetType().Assembly.GetManifestResourceStream("MDIWithImageBG.les_paul.jpg"))
    'CALCULATE THE TOP AND LEFT POSITION (CENTER) TO DRAW THE IMAGE
    Dim MyTop As Integer = 0
    Dim MyLeft As Integer = 0
    If MyImage.Height < Me.Height Then
    MyTop = Convert.ToInt32((Me.ClientSize.Height - MyImage.Height) / 2)
    End If
    If MyImage.Width < Me.Width Then
    MyLeft = Convert.ToInt32((Me.ClientSize.Width - MyImage.Width) / 2)
    End If
    'DRAW THE IMAGE ONTO THE MDI BACKGROUND
    e.Graphics.DrawImage(Image.FromStream(Me.GetType().Assembly.GetManifestResourceStream("MDIWithImageB G.les_paul.jpg")), MyLeft, MyTop)

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

    Re: MDI Background Image

    vb.net Code:
    1. Private mdiHost As MdiClient
    2. Private backgrounds As Image() = {My.Resources.MdiBackgroundImage1, _
    3.                                   My.Resources.MdiBackgroundImage2, _
    4.                                   My.Resources.MdiBackgroundImage3}
    5. Private backgroundIndex As Integer = -1
    6.  
    7. Private Sub Form1_Load(ByVal sender As Object, _
    8.                        ByVal e As EventArgs) Handles MyBase.Load
    9.     For Each ctl As Control In Me.Controls
    10.         If TypeOf ctl Is MdiClient Then
    11.             Me.mdiHost = DirectCast(ctl, MdiClient)
    12.             Exit For
    13.         End If
    14.     Next ctl
    15.  
    16.     Me.SetBackgroundImage()
    17. End Sub
    18.  
    19. Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles Timer1.Tick
    20.     Me.SetBackgroundImage()
    21. End Sub
    22.  
    23. Private Sub SetBackgroundImage()
    24.     Me.backgroundIndex += 1
    25.  
    26.     If Me.backgroundIndex = Me.backgrounds.Length Then
    27.         Me.backgroundIndex = 0
    28.     End If
    29.  
    30.     Me.mdiHost.BackgroundImage = Me.backgrounds(Me.backgroundIndex)
    31. 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

  17. #17
    Fanatic Member
    Join Date
    Sep 2007
    Posts
    839

    Re: MDI Background Image

    ok , i try this..

  18. #18
    Fanatic Member
    Join Date
    Sep 2007
    Posts
    839

    Re: MDI Background Image

    jmcilhinney, its' nice works finr... but i doesn't change the image...
    how to do the changing of images...

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

    Re: MDI Background Image

    Have you started your Timer? I asked you in one of the multitude of threads in which you've asked this same question whether you had read the documentation for the Timer class. You didn't answer that question but I would assume that the answer is NO.

    People here are happy to provide help in different ways. Personally, I'm a big believer in pointing people to where the information can be found and then I expect that if it's important enough to them they will go and read that information. The people who will make good developers are the ones who consider it important enough that they will go and read the information for themselves and try to make use of it, asking questions again if they are unable.
    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

  20. #20
    Fanatic Member
    Join Date
    Sep 2007
    Posts
    839

    Re: MDI Background Image

    sorry, not to do it again....

    jmcilhinney, the picture is set too big...

    how to minimize the size...?

  21. #21
    Fanatic Member
    Join Date
    Sep 2007
    Posts
    839

    Re: MDI Background Image

    the picture shown too big.. it's occupy the entire form.
    i want to show the picture in normal size and center to the screen...
    how to do it..?

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

    Re: MDI Background Image

    This is from the code example contained in the Help topic for the BackgroundImage property:
    Code:
       ' Assign a background image.
       button1.BackgroundImage = imageList1.Images(0)
    
       ' Specify the layout style of the background image. Tile is the default.
       button1.BackgroundImageLayout = ImageLayout.Center
    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

  23. #23
    Fanatic Member
    Join Date
    Sep 2007
    Posts
    839

    Re: MDI Background Image

    jmcilhinney, what you mean..? i used your code in post 16..

    and it work nice.. I'm almost there to what i want to be.. the only problem i got here is the picture is very big and it's occupy the entire form...

    now, how could make it center to the form and with a normal size or may size that not less than 4 inches height and width...

    Help me..

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

    Re: MDI Background Image

    Take another look at the code from my last post. Pay special attention to the bit in red:
    Code:
       ' Assign a background image.
       button1.BackgroundImage = imageList1.Images(0)
    
       ' Specify the layout style of the background image. Tile is the default.
       button1.BackgroundImageLayout = ImageLayout.Center
    Am I being too cryptic?
    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

  25. #25
    Fanatic Member
    Join Date
    Sep 2007
    Posts
    839

    Re: MDI Background Image

    then where i have to put this based on the code post 16 above:

    ' Assign a background image.
    button1.BackgroundImage = imageList1.Images(0)

    ' Specify the layout style of the background image. Tile is the default.
    button1.BackgroundImageLayout = ImageLayout.Center

  26. #26
    Fanatic Member
    Join Date
    Sep 2007
    Posts
    839

    Re: MDI Background Image

    because what happen here, again it's on top of mdichild form...

  27. #27
    Fanatic Member
    Join Date
    Sep 2007
    Posts
    839

    Re: MDI Background Image

    i used the code on on post 24 and 25...
    but it again go to the top of the mdi child..

    how to avoid it..?

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

    Re: MDI Background Image

    I'll tell you the reason that I avoid posting code a lot of the time: because too many people simply park their brain in neutral and expect to be able to copy the code, post it in their project and be on their merry way. Example code is just that: an example. You're supposed to look at the example and see the principle it is supposed to illustrate, then implement the same principle in your own project.

    You don't put THAT code anywhere. Look, that code is setting the BackgroundImage property of button1 and your code is setting the BackgroundImage of mdiHost. Now, if that code then sets the BackgroundImageLayout of button1 to Center, what do you suppose you should do in your code to get your background image centred, given that it's the background image of mdiHost we're talking about, NOT the background image of button1.
    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

  29. #29
    Fanatic Member
    Join Date
    Sep 2007
    Posts
    839

    Re: MDI Background Image

    yes that is what i'm doing here i'm not setting the background of the button1 in it's property but doing this code below..

    form_Load
    For Each ctl As Control In Me.Controls
    If TypeOf ctl Is MdiClient Then
    Me.mdiHost = DirectCast(ctl, MdiClient)
    Exit For
    End If

    Next ctl
    Timer1.Interval = 7000
    Timer1.Start()
    ' Me.SetBackgroundImage()


    Me.Button1.BackgroundImage = backgrounds(0)
    ' Specify the layout style of the background image. Tile is the default.
    button1.BackgroundImageLayout = ImageLayout.Center
    End Sub

    Private Sub SetBackgroundImage()
    Me.backgroundIndex += 1
    If Me.backgroundIndex = Me.backgrounds.Length Then
    Me.backgroundIndex = 0
    End If

    Me.Button1.BackgroundImage = Me.backgrounds(Me.backgroundIndex)

    End Sub

    Private sub Timer1_teck
    me.setbackgroundimage()
    end sub

    that is what i'm doing.. but again and the result is what i'm saying a while ago..

  30. #30
    Fanatic Member
    Join Date
    Sep 2007
    Posts
    839

    Re: MDI Background Image

    i put button1 here in my MDIParent then i set the image there..

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

    Re: MDI Background Image

    You are not suposed to be doing anything whatsoever to Button1. That's the point. You're supposed to set the BackgroundImage property of the MdiClient control, then you supposed to set the BackgroundImageLayout property of the same MdiClient control. Look at my code in post #16. Are there any Buttons mentioned there at all? No, the point is to display the image on the MdiClient control. As I said very, VERY clearly, the code in post #22 was an EXAMPLE only. It was intended to illustrate a principle, that principle being that you could set the BackgroundImage of a control and then set the BackgroundImageLayout of the same control. In the example it used a Button but in your project you're NOT using a Button; you're using an MdiClient. You were supposed to make the mental leap that you should be setting the BackgroundImageLayout property of THAT MdiClient.
    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

  32. #32
    Fanatic Member
    Join Date
    Sep 2007
    Posts
    839

    Re: MDI Background Image

    i'm sorry i can really understand... i'm just new in this program thats why i'm asking... i want to know it...

    how to set the BackgroundImage property of the MdiClient control, and to set the BackgroundImageLayout property of MdiClient control?

  33. #33
    Fanatic Member
    Join Date
    Sep 2007
    Posts
    839

    Re: MDI Background Image

    thank you very much... I'll try to do it until it work.... thank you very much for your help......

  34. #34
    Fanatic Member
    Join Date
    Sep 2007
    Posts
    839

    Re: MDI Background Image

    thanks you sir... I've already rate this thread..

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

    Re: MDI Background Image

    Quote Originally Posted by edgarbenilde
    how to set the BackgroundImage property of the MdiClient control
    You're already doing it. Did you read the code I posted?
    vb.net Code:
    1. Me.mdiHost.BackgroundImage = Me.backgrounds(Me.backgroundIndex)
    Quote Originally Posted by edgarbenilde
    and to set the BackgroundImageLayout property of MdiClient control?
    Mental leap. If this is how to set the BackgroundImage property of button1:
    Code:
    button1.BackgroundImage = imageList1.Images(0)
    and this is how to set the BackgroundImage of your MdiClient:
    Code:
    Me.mdiHost.BackgroundImage = Me.backgrounds(Me.backgroundIndex)
    and this is how to set the BackgroundImageLayout of button1 to Center:
    Code:
    button1.BackgroundImageLayout = ImageLayout.Center
    then how do you suppose you would set the BackgroundImageLayout of your MdiClient to Center?
    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

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