Minggu, 17 Februari 2013

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.


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


Sumber : http://bahrie27.wordpress.com/2010/04/10/visual-studio-net/http://bahrie27.wordpress.com/2010/04/10/visual-studio-net/

Tidak ada komentar:

Posting Komentar