Form Background

sathya.cs

Active member
Joined
May 24, 2009
Messages
31
Programming Experience
Beginner
:eek:How to remove or change the form back gorund image to "none" through runtime?
 
VB.NET:
Me.BackgroundImage.Dispose()
Me.BackgroundImage = Nothing
If you still want to use the Image object elsewhere then omit the first line.
Thanks u ..How to bring back the bgimage again after "Me.BackgroundImage = Nothing" alone..can how to have an imagelist image greater than 256 X 256?
 
You should omit the Dispose line and assign the Image to a variable before setting the BackgroundImage to Nothing. You can then assign the variable back to the BackgroundImage property later.

I would strongly suggest that you don't use an ImageList unless you need to, i.e. you are using a TreeView or ListView or some other control that requires it. Such controls only use small images. Otherwise just add the images to your resources and then create an array or collection at run time. That way you can use any images you want.
 
i used the below but didn't work..(i am just a beginner)

Private Sub bg_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bg.CheckedChanged
Dim a As Image
a = BackgroundImage
If bg.Checked = False Then

Me.BackgroundImage = Nothing

Else
Me.BackgroundImage = a

End If
End Sub
 
It doesn't work because you are using a local variable. Your 'a' variable doesn't exist outside the method so how can it store the Image outside the method? You need a variable that exists outside that method, i.e. a member variable.
 
At first time it worked but after some change its not working..i tried a lot by againg with old back up project...but still getting trouble..can i upload the project to you....if mail id?can you take a look on project?
<Code>
Public Class main

Dim a As Image
-----------------------------------------------------------------------------------------------------------------------

Private Sub bg_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bg.CheckedChanged
a = BackgroundImage
If bg.Checked = False Then

Me.BackgroundImage = Nothing

Else

Me.BackgroundImage = a

End If
End Sub
End Class
-----------------------------------------------------------------------------------------------------------------------
 
You are simply assigning the BackgroundImage to 'a' no matter what. What if the BackgroundImage is Nothing? You'll be making 'a' Nothing too and then your Image is lost.

You're only using a single Image, right? You don't need to assign that same Image to 'a' every time the CheckBox is checked or unchecked. You only need to assign it once, when the form loads. Then, when the CheckBox is checked or unchecked, you either assign that Image or Nothing to the BackgroundImage property.

Also, even if this is just a test you should use a descriptive name for your variable, not just 'a'. Get into good habits.
 
Back
Top