In: Computer Science
Write a program to carry out the stated task: When one of the buttons is pressed, the face changes to a smiling face [emoticon :-) ] or a frowning face [emoticon :-(]. Written in Visual Basic.
Below is the form:
Name of important controls:
PictureBox: pbImage
Button: btnChange
Below is the Vb code:
Imports System.IO
Public Class Form1
Private Sub btnChange_Click(sender As
Object, e As EventArgs) Handles btnChange.Click
'Change the image on
button click
If pbImage.Tag = 0
Then
pbImage.Image = Image.FromFile("frown.png")
pbImage.Tag = 1
ElseIf pbImage.Tag = 1
Then
pbImage.Image = Image.FromFile("smile.png")
pbImage.Tag = 0
End If
End Sub
Private Sub Form1_Load(sender As
Object, e As EventArgs) Handles MyBase.Load
' set Tag to 0
initially
pbImage.Tag
= 0
End Sub
End Class
Please note it expects the file name to be 'smile.png' and 'frown.png'. It should be in the folder where the .exe file is. If it is somewhere else, change it in the code accordingly.
Below are the sample outputs:
Upon clicking the "Change" button, it will toggle the image as below:
This completes the requirement. Let me know if you have any questions.
Thanks!