Visual Basic 2008 Tutorials
www.reflectionforbrain.com

 

Back | Index

Change Background Image and Style

In this tutorial, you will learn how to change a form background, and choose a style.



For this tutorial you need a button, 5 radio buttons and OpenFileDialog

Change Background button click event:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim OpenFileDialog1 As New OpenFileDialog

With OpenFileDialog1

.CheckFileExists = True

.ShowReadOnly = False

.Filter = "All Files|*.*|Bitmap Files (*)|*.bmp;*.gif;*.jpg"

.FilterIndex = 2

If .ShowDialog = DialogResult.OK Then

Me.BackgroundImage = Image.FromFile(.FileName)

End If

End With

End Sub


Tile Style radio button code:

Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged

Me.BackgroundImageLayout = ImageLayout.Tile

End Sub


Center:

Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged

Me.BackgroundImageLayout = ImageLayout.Center

End Sub


Stretch:

Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged

Me.BackgroundImageLayout = ImageLayout.Stretch

End Sub


Zoom:

Private Sub RadioButton4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton4.CheckedChanged

Me.BackgroundImageLayout = ImageLayout.Zoom

End Sub


To remove background image:

Private Sub RadioButton5_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton5.CheckedChanged

Me.BackgroundImage = Nothing

End Sub