stretching backgroundimage

Heppen

Member
Joined
Dec 23, 2005
Messages
9
Programming Experience
1-3
I have an mdi application and on the parent form i have a background image that is want to strech to the whole form. but when i load tha appplic the background image is placed abreast...

thsi procedure i found and it works but after this prodecure is something else called (i don't know what) so the background image is placed abreast again.... at the messagebox.show(0) the image is strecht over the form but when the form is fully loaded it isn't...

VB.NET:
[SIZE=2][COLOR=#0000ff]Protected[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Overloads[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Overrides[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] OnPaintBackground([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] pevent [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] PaintEventArgs)
[/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Not[/COLOR][/SIZE][SIZE=2] ([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].BackgroundImage [/SIZE][SIZE=2][COLOR=#0000ff]Is[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Nothing[/COLOR][/SIZE][SIZE=2]) [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]  pevent.Graphics.InterpolationMode =   System.Drawing.Drawing2D.InterpolationMode.Low
  pevent.[SIZE=2][/SIZE]Graphics.Clear([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].BackColor)
  pevent.Graphics.DrawImage([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].BackgroundImage, 0, 0,[/SIZE][SIZE=2][COLOR=#0000ff]   Me[/COLOR][/SIZE][SIZE=2].ClientRectangle.Width, [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].ClientRectangle.Height)
[/SIZE][SIZE=2][COLOR=#0000ff]Else
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]  MyBase[/COLOR][/SIZE][SIZE=2].OnPaintBackground(pevent)
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2]MessageBox.Show(0)
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff][COLOR=#000000]
[/COLOR][/COLOR][/SIZE]

please help
 
The background of the actual parent form is not visible because it is covered by an MdiClient control. To see the background of the form it is having to push the MdiClient object partially out of the way. You cannot access this control at design time as you aren't supposed to manipulate it. I'd suggest that you loop through all the controls on the form in the Laod event handler and then set the MdiClient's BackgroundImage property there:
VB.NET:
For Each ctl As Control In Me.Controls
    If TypeOf ctl Is MdiClient Then
        ctl.BackgroundImage = someImage
        Exit For
    End If
Next ctl
 
jmcilhinney said:
The background of the actual parent form is not visible because it is covered by an MdiClient control. To see the background of the form it is having to push the MdiClient object partially out of the way. You cannot access this control at design time as you aren't supposed to manipulate it. I'd suggest that you loop through all the controls on the form in the Laod event handler and then set the MdiClient's BackgroundImage property there:
VB.NET:
For Each ctl As Control In Me.Controls
    If TypeOf ctl Is MdiClient Then
        ctl.BackgroundImage = someImage
        Exit For
    End If
Next ctl

the image of the mdiclient is already the same but i want to strech the image of the mdiclient so that i see only onetime the image and not more images abreast. so how do i strech the backgroundimage of the mdiclient ??
 
Dunno if this is worth a try, at the moment you are drawing yuor image onto the mdicontrol directly through its paint event. Instead of using the already provided graphics surface create a new one and draw your image on that. i.e

VB.NET:
IfNot (Me.BackgroundImage IsNothing) Then
Dim G as graphics  = me.creategraphics

  G.InterpolationMode =   System.Drawing.Drawing2D.InterpolationMode.Low
  G.Clear(Me.BackColor)
  G.DrawImage(Me.BackgroundImage, 0, 0,   Me.ClientRectangle.Width, Me.ClientRectangle.Height)
Else
  MyBase.OnPaintBackground(pevent)
EndIf
MessageBox.Show(0)
EndSub

To be honest i agree with jmcilhinney and you should not try to manipulate the mdi background. But hey if my idea doesnt work and you do figure out how to do it, i would be interested in the answer.
 
Back
Top