[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 :confused:
(I mean dark gray region in MDI form)
Do you know any solution?
Re: [2005] Background image in MDIForm
use child forms bringtofront
Re: [2005] Background image in MDIForm
Code is for childforms:
Code:
frmStok.MdiParent = Me
frmStok.Show()
frmStok.BringToFront()
It should work?
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.
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...
http://img163.imageshack.us/img163/4...dasdqt3.th.jpg
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.
Re: [2005] Background image in MDIForm
Odd that it works perfectly for me. Post your EXACT code.
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...
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.
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...?
Re: [2005] Background image in MDIForm
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.
Re: [2005] Background image in MDIForm
thanks ... and sorry for my bad explanation and english... :)
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.
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?
Re: [2005] Background image in MDIForm
For who cares it I have finally found a solution...
vb Code:
Private Sub frmStok_Move(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Move
Dim MDI As frmMDI = Me.MdiParent
MDI.LogoKoy(1) 'puts the picture
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.
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.
Re: [RESOLVED] [2005] Background image in MDIForm
yes the event is missing too. However it is "resolved" and thank you a lot!!!
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.
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...