Dua Kondisi : IF .... THEN .. ELSE....
Jika satu kondisi terpenuhi maka code result akan dieksekusi dan jika tidak maka akan mencari
code lain untuk dieksekusi.
Sintaks :
If [kondisi] Then [Result] ...Else [Result] ...End If
Contoh:
UI:
Code:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Button1.Text = "Apply Format"
CheckBox1.Text = "Red Font"
CheckBox2.Text = "Lightened"
Label1.Text = "SAMPLE TEXT"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
If CheckBox1.Checked = True Then
Label1.ForeColor = Color.Red
Else
Label1.ForeColor = Color.Black
End If
If CheckBox2.Checked = True Then
Label1.BackColor = Color.Yellow
Else
Label1.BackColor = Color.FromKnownColor(KnownColor.Control)
End If
End Sub
End Class Private Sub Form1_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load Button1.Text = "Apply Format" CheckBox1.Text = "Red Font" CheckBox2.Text = "Lightened" Label1.Text = "SAMPLE TEXT" End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click If CheckBox1.Checked = True Then Label1.ForeColor = Color.Red Else Label1.ForeColor = Color.Black End If If CheckBox2.Checked = True Then Label1.BackColor = Color.Yellow Else Label1.BackColor = Color.FromKnownColor(KnownColor.Control) End If End SubEnd Class
Runtime:
Sangat menarik kan.. ikuti terus pembelajaran kami selanjutnya........
0 komentar:
Posting Komentar