NOTEPAD DENGAN VB.NET 2003

ini merupakan tugas matakuliah pemrograman vb.net 2003. ini tampilan di dalam form vb.net

lihat apa saja pallete yang dibutuhkan..

inilah sourcecodenya..

Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.IO
Imports System.Drawing.Printing
Imports Microsoft.Win32

Namespace NotePadeBahrie
    Public Class Form1
        Inherits System.Windows.Forms.Form
        Private components As System.ComponentModel.Container
        Private WithEvents mnuAbout As System.Windows.Forms.MenuItem
        Private WithEvents mnuSetBackCol As System.Windows.Forms.MenuItem
        Private menuItem7 As System.Windows.Forms.MenuItem
        Private menuItem6 As System.Windows.Forms.MenuItem
        Private WithEvents mnuSetFontColor As System.Windows.Forms.MenuItem
        Private colorDialog1 As System.Windows.Forms.ColorDialog
        Private fontDialog1 As System.Windows.Forms.FontDialog
        Private WithEvents mnuSetFont As System.Windows.Forms.MenuItem
        Private WithEvents mnuWordWrap As System.Windows.Forms.MenuItem
        Private WithEvents MnuTimeDate As System.Windows.Forms.MenuItem
        Private WithEvents mnuSelectAll As System.Windows.Forms.MenuItem
        Private menuItem5 As System.Windows.Forms.MenuItem
        Private WithEvents mnuDelete As System.Windows.Forms.MenuItem
        Private WithEvents mnuCut As System.Windows.Forms.MenuItem
        Private menuItem2 As System.Windows.Forms.MenuItem
        Private WithEvents mnuUndo As System.Windows.Forms.MenuItem
        Private pageSetupDialog1 As System.Windows.Forms.PageSetupDialog
        Private printDialog1 As System.Windows.Forms.PrintDialog
        Private saveFileDialog1 As System.Windows.Forms.SaveFileDialog
        Private openFileDialog1 As System.Windows.Forms.OpenFileDialog
        Private WithEvents mnuExit As System.Windows.Forms.MenuItem
        Private menuItem12 As System.Windows.Forms.MenuItem
        Private WithEvents mnuPrint As System.Windows.Forms.MenuItem
        Private WithEvents mnuPageSetUp As System.Windows.Forms.MenuItem
        Private menuItem9 As System.Windows.Forms.MenuItem
        Private WithEvents textBox1 As System.Windows.Forms.TextBox
        Private WithEvents mnuPaste As System.Windows.Forms.MenuItem
        Private WithEvents mnuCopy As System.Windows.Forms.MenuItem
        Private mnuEdit As System.Windows.Forms.MenuItem
        Private WithEvents mnuSaveAs As System.Windows.Forms.MenuItem
        Private WithEvents mnuSave As System.Windows.Forms.MenuItem
        Private WithEvents mnuOpen As System.Windows.Forms.MenuItem
        Private WithEvents mnuNew As System.Windows.Forms.MenuItem
        Private mnuFile As System.Windows.Forms.MenuItem
        Private mainMenu1 As System.Windows.Forms.MainMenu

        Private blnSaveChkFlag As Boolean

        Public Sub New()
            InitializeComponent()

            '
            textBox1.Width = Me.Width
            textBox1.Height = Me.Height
            GetSettings()
        End Sub

        Protected Overloads Sub Dispose(ByVal disposing As Boolean)
            If disposing Then
                If Not (components Is Nothing) Then
                    components.Dispose()
                End If
            End If
            MyBase.Dispose(disposing)
        End Sub

        Private Sub InitializeComponent()
            Me.mnuPaste = New System.Windows.Forms.MenuItem
            Me.mnuSetFontColor = New System.Windows.Forms.MenuItem
            Me.MnuTimeDate = New System.Windows.Forms.MenuItem
            Me.colorDialog1 = New System.Windows.Forms.ColorDialog
            Me.mnuSaveAs = New System.Windows.Forms.MenuItem
            Me.mnuSetBackCol = New System.Windows.Forms.MenuItem
            Me.mnuNew = New System.Windows.Forms.MenuItem
            Me.mnuAbout = New System.Windows.Forms.MenuItem
            Me.pageSetupDialog1 = New System.Windows.Forms.PageSetupDialog
            Me.mnuCopy = New System.Windows.Forms.MenuItem
            Me.mnuExit = New System.Windows.Forms.MenuItem
            Me.mnuUndo = New System.Windows.Forms.MenuItem
            Me.menuItem12 = New System.Windows.Forms.MenuItem
            Me.mnuPrint = New System.Windows.Forms.MenuItem
            Me.mnuFile = New System.Windows.Forms.MenuItem
            Me.mnuOpen = New System.Windows.Forms.MenuItem
            Me.mnuSave = New System.Windows.Forms.MenuItem
            Me.menuItem9 = New System.Windows.Forms.MenuItem
            Me.mnuPageSetUp = New System.Windows.Forms.MenuItem
            Me.mnuWordWrap = New System.Windows.Forms.MenuItem
            Me.mnuCut = New System.Windows.Forms.MenuItem
            Me.menuItem7 = New System.Windows.Forms.MenuItem
            Me.menuItem6 = New System.Windows.Forms.MenuItem
            Me.mnuSetFont = New System.Windows.Forms.MenuItem
            Me.mnuSelectAll = New System.Windows.Forms.MenuItem
            Me.menuItem2 = New System.Windows.Forms.MenuItem
            Me.menuItem5 = New System.Windows.Forms.MenuItem
            Me.saveFileDialog1 = New System.Windows.Forms.SaveFileDialog
            Me.textBox1 = New System.Windows.Forms.TextBox
            Me.mnuDelete = New System.Windows.Forms.MenuItem
            Me.mnuEdit = New System.Windows.Forms.MenuItem
            Me.mainMenu1 = New System.Windows.Forms.MainMenu
            Me.fontDialog1 = New System.Windows.Forms.FontDialog
            Me.openFileDialog1 = New System.Windows.Forms.OpenFileDialog
            Me.printDialog1 = New System.Windows.Forms.PrintDialog
            Me.SuspendLayout()
            'hasil generate
            'mnuPaste

            Me.mnuPaste.Index = 4
            Me.mnuPaste.Shortcut = System.Windows.Forms.Shortcut.CtrlV
            Me.mnuPaste.Text = "&Paste"
            '
            'mnuSetFontColor
            '
            Me.mnuSetFontColor.Index = 1
            Me.mnuSetFontColor.Text = "Set Font C&olor..."
            '
            'MnuTimeDate
            '
            Me.MnuTimeDate.Index = 8
            Me.MnuTimeDate.Shortcut = System.Windows.Forms.Shortcut.F5
            Me.MnuTimeDate.Text = "&Time/Date"
            '
            'mnuSaveAs
            '
            Me.mnuSaveAs.Index = 3
            Me.mnuSaveAs.Text = "Save &As..."
            '
            'mnuSetBackCol
            '
            Me.mnuSetBackCol.Index = 2
            Me.mnuSetBackCol.Text = "Set &Background Color..."
            '
            'mnuNew
            '
            Me.mnuNew.Index = 0
            Me.mnuNew.Shortcut = System.Windows.Forms.Shortcut.CtrlN
            Me.mnuNew.Text = "&New"
            '
            'mnuAbout
            '
            Me.mnuAbout.Index = 0
            Me.mnuAbout.Text = "&About"
            '
            'mnuCopy
            '
            Me.mnuCopy.Index = 3
            Me.mnuCopy.Shortcut = System.Windows.Forms.Shortcut.CtrlC
            Me.mnuCopy.Text = "&Copy"
            '
            'mnuExit
            '
            Me.mnuExit.Index = 8
            Me.mnuExit.Shortcut = System.Windows.Forms.Shortcut.AltF4
            Me.mnuExit.Text = "E&xit"
            '
            'mnuUndo
            '
            Me.mnuUndo.Index = 0
            Me.mnuUndo.Shortcut = System.Windows.Forms.Shortcut.CtrlZ
            Me.mnuUndo.Text = "&Undo"
            '
            'menuItem12
            '
            Me.menuItem12.Index = 7
            Me.menuItem12.Text = "-"
            '
            'mnuPrint
            '
            Me.mnuPrint.Index = 6
            Me.mnuPrint.Shortcut = System.Windows.Forms.Shortcut.CtrlP
            Me.mnuPrint.Text = "&Print"
            '
            'mnuFile
            '
            Me.mnuFile.Index = 0
            Me.mnuFile.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuNew, Me.mnuOpen, Me.mnuSave, Me.mnuSaveAs, Me.menuItem9, Me.mnuPageSetUp, Me.mnuPrint, Me.menuItem12, Me.mnuExit})
            Me.mnuFile.Text = "&File"
            '
            'mnuOpen
            '
            Me.mnuOpen.Index = 1
            Me.mnuOpen.Shortcut = System.Windows.Forms.Shortcut.CtrlO
            Me.mnuOpen.Text = "&Open..."
            '
            'mnuSave
            '
            Me.mnuSave.Index = 2
            Me.mnuSave.Shortcut = System.Windows.Forms.Shortcut.CtrlS
            Me.mnuSave.Text = "&Save"
            '
            'menuItem9
            '
            Me.menuItem9.Index = 4
            Me.menuItem9.Text = "-"
            '
            'mnuPageSetUp
            '
            Me.mnuPageSetUp.Index = 5
            Me.mnuPageSetUp.Text = "Page Se&tup..."
            '
            'mnuWordWrap
            '
            Me.mnuWordWrap.Index = 9
            Me.mnuWordWrap.Text = "&Word Wrap"
            '
            'mnuCut
            '
            Me.mnuCut.Index = 2
            Me.mnuCut.Shortcut = System.Windows.Forms.Shortcut.CtrlX
            Me.mnuCut.Text = "C&ut"
            '
            'menuItem7
            '
            Me.menuItem7.Index = 3
            Me.menuItem7.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuAbout})
            Me.menuItem7.Text = "&Help"
            '
            'menuItem6
            '
            Me.menuItem6.Index = 2
            Me.menuItem6.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuSetFont, Me.mnuSetFontColor, Me.mnuSetBackCol})
            Me.menuItem6.Text = "&Tools"
            '
            'mnuSetFont
            '
            Me.mnuSetFont.Index = 0
            Me.mnuSetFont.Text = "Set &Font..."
            '
            'mnuSelectAll
            '
            Me.mnuSelectAll.Index = 7
            Me.mnuSelectAll.Shortcut = System.Windows.Forms.Shortcut.CtrlA
            Me.mnuSelectAll.Text = "Select &All"
            '
            'menuItem2
            '
            Me.menuItem2.Index = 1
            Me.menuItem2.Text = "-"
            '
            'menuItem5
            '
            Me.menuItem5.Index = 6
            Me.menuItem5.Text = "-"
            '
            'saveFileDialog1
            '
            Me.saveFileDialog1.CheckFileExists = True
            Me.saveFileDialog1.DefaultExt = "txt"
            Me.saveFileDialog1.FileName = "doc1"
            Me.saveFileDialog1.Filter = "Text files (*.txt)|*.txt"
            Me.saveFileDialog1.RestoreDirectory = True
            '
            'textBox1
            '
            Me.textBox1.AutoSize = False
            Me.textBox1.Location = New System.Drawing.Point(0, 0)
            Me.textBox1.Multiline = True
            Me.textBox1.Name = "textBox1"
            Me.textBox1.Size = New System.Drawing.Size(440, 304)
            Me.textBox1.TabIndex = 0
            Me.textBox1.Text = ""
            '
            'mnuDelete
            '
            Me.mnuDelete.Index = 5
            Me.mnuDelete.Shortcut = System.Windows.Forms.Shortcut.Del
            Me.mnuDelete.Text = "De&lete"
            '
            'mnuEdit
            '
            Me.mnuEdit.Index = 1
            Me.mnuEdit.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuUndo, Me.menuItem2, Me.mnuCut, Me.mnuCopy, Me.mnuPaste, Me.mnuDelete, Me.menuItem5, Me.mnuSelectAll, Me.MnuTimeDate, Me.mnuWordWrap})
            Me.mnuEdit.Text = "&Edit"
            '
            'mainMenu1
            '
            Me.mainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuFile, Me.mnuEdit, Me.menuItem6, Me.menuItem7})
            '
            'openFileDialog1
            '
            Me.openFileDialog1.DefaultExt = "*.txt"
            Me.openFileDialog1.Filter = "Text files (*.txt)|*.txt"
            Me.openFileDialog1.RestoreDirectory = True
            Me.openFileDialog1.Title = "Open File"
            '
            'Form1
            '
            Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
            Me.ClientSize = New System.Drawing.Size(576, 377)
            Me.Controls.Add(Me.textBox1)
            Me.Menu = Me.mainMenu1
            Me.Name = "Form1"
            Me.Text = "NotePad Bahrie"
            Me.ResumeLayout(False)

        End Sub 'InitializeComponent

        Protected Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
            textBox1.Width = Me.Width
            textBox1.Height = Me.Height
        End Sub 'supaya ukuran tampilannya flaksibel

        Protected Sub mnuAbout_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuAbout.Click
            Dim abt = New about
            abt.ShowDialog()
        End Sub 'menu abaut.

        Protected Sub mnuSetBackCol_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuSetBackCol.Click
            colorDialog1.ShowDialog()
            textBox1.BackColor = colorDialog1.Color
        End Sub

        Protected Sub mnuFontColor_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuSetFontColor.Click
            colorDialog1.ShowDialog()
            textBox1.ForeColor = colorDialog1.Color
        End Sub

        Protected Sub mnuSetFont_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuSetFont.Click
            fontDialog1.ShowDialog()
            textBox1.Font = fontDialog1.Font
        End Sub

        Protected Sub mnuWordWrap_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuWordWrap.Click
            textBox1.WordWrap = Not textBox1.WordWrap
            mnuWordWrap.Checked = Not mnuWordWrap.Checked
        End Sub

        Protected Sub MnuTimeDate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MnuTimeDate.Click
            textBox1.Text = textBox1.Text + DateTime.Now.ToLongTimeString() + DateTime.Now.ToLongDateString()
            textBox1.SelectionLength = textBox1.Text.Length
            textBox1.SelectionStart = textBox1.Text.Length
        End Sub

        Protected Sub mnuSelectAll_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuSelectAll.Click
            textBox1.SelectAll()
        End Sub

        Protected Sub mnuDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuDelete.Click
            textBox1.SelectedText = ""
        End Sub

        Protected Sub mnuCut_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuCut.Click
            textBox1.Cut()
        End Sub

        Protected Sub mnuUndo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuUndo.Click
            textBox1.Undo()
        End Sub

        Protected Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
            'ngecek saat diklose
            If checkUnSavedData() = False Then
                e.Cancel = True
                Return
            End If
            SaveSettings() 'Save setting ke registry
        End Sub '

        Protected Sub textBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles textBox1.TextChanged
            blnSaveChkFlag = True
        End Sub

        Protected Sub mnuPrint_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuPrint.Click

            printDialog1.AllowPrintToFile = True
            Dim docPrn As New PrintDocument
            docPrn.DocumentName = textBox1.Text
            printDialog1.Document = docPrn
            If printDialog1.ShowDialog() = DialogResult.OK Then
                Try
                    docPrn.Print()
                Catch
                End Try
            End If
        End Sub

        Protected Sub mnuPageSetUp_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuPageSetUp.Click
            Dim docPrn As New PrintDocument
            docPrn.DocumentName = textBox1.Text
            pageSetupDialog1.Document = docPrn
            pageSetupDialog1.ShowDialog()
        End Sub

        Protected Sub mnuSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuSave.Click
            SaveFile()
        End Sub

        Protected Sub mnuExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuExit.Click

            If checkUnSavedData() Then
                Me.Close()
            End If
        End Sub

        Private Function SaveFile() As Boolean
            Try
                Dim fName As String
                Dim dlgR As DialogResult = saveFileDialog1.ShowDialog()
                If dlgR = DialogResult.Cancel Then

                    blnSaveChkFlag = True
                    Return False
                End If
                fName = saveFileDialog1.FileName
                Dim fSave As New StreamWriter(fName)
                fSave.WriteLine(textBox1.Text)
                fSave.Flush()
                fSave.Close()
                Me.Text = fName
                blnSaveChkFlag = False
                Return True
            Catch
            End Try
        End Function

        Protected Sub mnuSaveAs_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuSaveAs.Click

            SaveFile()
        End Sub

        Protected Sub mnuOpen_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuOpen.Click
            If checkUnSavedData() Then
                openFileDialog1.ShowDialog()
                Try
                    If File.Exists(openFileDialog1.FileName) Then
                        Dim o As StreamReader = File.OpenText(openFileDialog1.FileName)
                        textBox1.Text = o.ReadToEnd()
                    End If
                    textBox1.SelectionStart = 0
                    textBox1.SelectionLength = 0
                    blnSaveChkFlag = False
                Catch
                End Try
            End If
        End Sub

        Protected Sub mnuPaste_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuPaste.Click

            Dim iData As IDataObject = Clipboard.GetDataObject()

            If iData.GetDataPresent(DataFormats.Text) Then
                textBox1.SelectedText = CType(iData.GetData(DataFormats.Text), [String])
            End If
        End Sub

        Protected Sub mnuCopy_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuCopy.Click
            Clipboard.SetDataObject(textBox1.SelectedText, True)
        End Sub

        Private Function checkUnSavedData() As Boolean
            If blnSaveChkFlag = True Then
                Dim dlgRes As DialogResult
                dlgRes = MessageBox.Show("File akan mengalami perubahan, Simpan apa tidak ??", "NotePad_Bahrie", MessageBoxButtons.YesNoCancel)

                Select Case dlgRes
                    Case DialogResult.Yes

                        Return SaveFile()
                    Case DialogResult.No
                        blnSaveChkFlag = False
                        Return True
                    Case DialogResult.Cancel
                        Return False
                End Select
            End If
            Return True
        End Function

        Protected Sub mnuNew_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuNew.Click

            If checkUnSavedData() Then
                textBox1.Clear() 'sama aja dengan textBox1.Text="";
                blnSaveChkFlag = False
                Me.Text = "Untitled - NotePad Bahrie"
            End If
        End Sub

        Private Sub SaveSettings()

            Try

                Dim reKSubKey As RegistryKey = Registry.LocalMachine
                reKSubKey.CreateSubKey("Bahrie")

                reKSubKey.SetValue("FontName", textBox1.Font.FontFamily.GetName(0))
                reKSubKey.SetValue("FontSize", Convert.ToString(textBox1.Font.Size))

                reKSubKey.SetValue("ForeCol", Convert.ToString(textBox1.ForeColor.ToArgb()))

                reKSubKey.SetValue("BackCol", Convert.ToString(textBox1.BackColor.ToArgb()))
            Catch
            End Try
        End Sub

        Private Sub GetSettings()

            Try
                Dim reK As RegistryKey = Registry.LocalMachine
                reK.OpenSubKey("Bahrie")

                textBox1.Font = New System.Drawing.Font(reK.GetValue("FontName").ToString(), Convert.ToSingle(reK.GetValue("FontSize")))
                textBox1.ForeColor = System.Drawing.Color.FromArgb(Convert.ToInt32(reK.GetValue("ForeCol")))
                textBox1.BackColor = System.Drawing.Color.FromArgb(Convert.ToInt32(reK.GetValue("BackCol")))
            Catch
            End Try
        End Sub

        Public Overloads Shared Sub Main(ByVal args() As String)
            Application.Run(New Form1)
        End Sub 'Main

    End Class
End Namespace

dan inilah gambaran hasilnya :

sourcecode dapat anda download disini.

sumber: google.com šŸ˜‰

1 Komentar (+add yours?)

  1. mbahsomo
    Jun 04, 2010 @ 14:39:27

    Hebat mas Kuliah dimana nih ? kok banyak tugas VB.NET

    Balas

Tinggalkan komentar