Saterdag 04 Januarie 2014

visual studio.net


Mulai belajar VISUAL STUDIO.NET


Disini saya akan berbagi ilmu saya tentang vs.net(VisualStudio.Net) yang saya terima dipraktikum hari jumat 13.30 Wib 9/4/10 diLab.
tulisan ini membahas tentang explorasi vs.net supaya kita lebih mengenal fitur-fiturnya dan mengetahui kemudahannya..
disini kita akan membuat dua buah form. form yang pertama memuat halaman depan yang diberi nama hello dan form kedua diberi nama message. ikuti langkah-langkahnya serta lihat gambar-gambarnya:

komponen gambar diatas:
Form1, MainMenu1, ToolTip1, ColorDialog1, Label1, Button1, Button2, Button3. Propertinya disesuakan sendiri.
dan bila dijalankan seperti ini gambarnya:

setelah itu buat form yang kedua.

komponen form diatas:
form2, MainMenu1, GroupBox1, Label1, Label2, TextBox1, RichTextbox1,GroupBox2,RadioButton1,RadioButton2,RadioButton3,
PictureBox1,Label3,Label4,CheckButton1,Button1,Button2
sebelum masuk ke script form1 dan form2 kita harus buat dulu modul
dengan cara. arahkan kursor keatas projek kuliah2 trus klik kanan–>add–>add Module. dan isi dengan syntax seperti dibawah ini.

1
2
3
Module _Module
    Public AppPath As String = Replace(Replace(Replace(Application.ExecutablePath, Application.ProductName + ".EXE", ""), Application.ProductName + ".exe", ""), Application.ProductName + ".exe", "")
End Module
dan untuk form1nya seperti dibawah ini.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
Public Class Form1
    Inherits System.Windows.Forms.Form
 
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Try
            If ColorDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
                Me.BackColor = ColorDialog1.Color
                Dim sw As New System.IO.StreamWriter(AppPath & ("Setting2.txt"))
                Dim a As String = Hex(ColorDialog1.Color.ToArgb)
                a = a.Substring(2)
                sw.WriteLine("#" & a)
                sw.Close() 'Menutup file
                System.IO.File.Delete(AppPath & ("Setting.txt"))
                System.IO.File.Move(AppPath & ("Setting2.txt"), AppPath & ("Setting.txt"))
 
            End If
        Catch ex As Exception
 
        End Try
    End Sub
 
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Application.Exit()
 
    End Sub
 
    Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click
        Dim message As New Form2
        message.ShowDialog()
 
    End Sub
 
    Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
        Label1.Text = "pertemuan pertama"
 
    End Sub
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            If System.IO.File.Exists(AppPath & ("Setting.txt")) = False Then
                Dim sw As New System.IO.StreamWriter(AppPath & ("Setting.txt"))
                Dim c As System.Drawing.Color = System.Drawing.ColorTranslator.FromHtml("Control")
                sw.WriteLine("#" & Hex(c.ToArgb))
                sw.Close()
            Else
                Dim color As String
                Dim sr As New System.IO.StreamReader(AppPath & ("Setting.txt"))
                color = sr.ReadLine()
                sr.Close()
                Dim color2 As System.Drawing.Color = System.Drawing.ColorTranslator.FromHtml(color)
                Me.BackColor = color2
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
 
        End Try
    End Sub
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Dim sw As New System.IO.StreamWriter(AppPath & ("Setting2.txt"))
            Dim color2 As System.Drawing.Color = System.Drawing.ColorTranslator.FromHtml("Control")
 
            Me.BackColor = color2
            sw.WriteLine("#" & Hex(color2.ToArgb))
            sw.Close()
            System.IO.File.Delete(AppPath & ("Setting.txt"))
            System.IO.File.Move(AppPath & ("Setting2.txt"), AppPath & ("Setting.txt"))
 
        Catch ex As Exception
            MsgBox(ex.Message)
 
        End Try
    End Sub
End Class
serta form2nya seperti dibawah ini
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
Public Class Form2
    Inherits System.Windows.Forms.Form
 
    Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click
        Form2.ActiveForm.Visible = False
 
    End Sub
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Label4.Text = "dari : " & TextBox1.Text & " ,pesannya : " & RichTextBox1.Text
 
    End Sub
 
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Label4.Text = " "
        TextBox1.Text = " "
        RichTextBox1.Text = " "
 
    End Sub
 
    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
        If CheckBox1.Checked = False Then
            Label4.Visible = True
        Else
            Label4.Visible = False
 
        End If
    End Sub
 
    Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
        If PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage Then
            PictureBox1.SizeMode = PictureBoxSizeMode.Normal
        ElseIf PictureBox1.SizeMode = PictureBoxSizeMode.Normal Then
            PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
        End If
    End Sub
 
    Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
        Label4.ForeColor = Color.Red
 
    End Sub
 
    Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
        Label4.ForeColor = Color.Green
 
    End Sub
 
    Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged
        Label4.ForeColor = Color.Black
    End Sub
End Class
tampilan jadinya seperti ini:


Geen opmerkings nie:

Plaas 'n opmerking