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.
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...
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.
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
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...
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...
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.
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.
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)
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.
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
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
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.
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
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.