Minggu, 17 Februari 2013

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..


001Imports System
002Imports System.Drawing
003Imports System.Collections
004Imports System.ComponentModel
005Imports System.Windows.Forms
006Imports System.Data
007Imports System.IO
008Imports System.Drawing.Printing
009Imports Microsoft.Win32
010 
011Namespace NotePadeBahrie
012    Public Class Form1
013        Inherits System.Windows.Forms.Form
014        Private components As System.ComponentModel.Container
015        Private WithEvents mnuAbout As System.Windows.Forms.MenuItem
016        Private WithEvents mnuSetBackCol As System.Windows.Forms.MenuItem
017        Private menuItem7 As System.Windows.Forms.MenuItem
018        Private menuItem6 As System.Windows.Forms.MenuItem
019        Private WithEvents mnuSetFontColor As System.Windows.Forms.MenuItem
020        Private colorDialog1 As System.Windows.Forms.ColorDialog
021        Private fontDialog1 As System.Windows.Forms.FontDialog
022        Private WithEvents mnuSetFont As System.Windows.Forms.MenuItem
023        Private WithEvents mnuWordWrap As System.Windows.Forms.MenuItem
024        Private WithEvents MnuTimeDate As System.Windows.Forms.MenuItem
025        Private WithEvents mnuSelectAll As System.Windows.Forms.MenuItem
026        Private menuItem5 As System.Windows.Forms.MenuItem
027        Private WithEvents mnuDelete As System.Windows.Forms.MenuItem
028        Private WithEvents mnuCut As System.Windows.Forms.MenuItem
029        Private menuItem2 As System.Windows.Forms.MenuItem
030        Private WithEvents mnuUndo As System.Windows.Forms.MenuItem
031        Private pageSetupDialog1 As System.Windows.Forms.PageSetupDialog
032        Private printDialog1 As System.Windows.Forms.PrintDialog
033        Private saveFileDialog1 As System.Windows.Forms.SaveFileDialog
034        Private openFileDialog1 As System.Windows.Forms.OpenFileDialog
035        Private WithEvents mnuExit As System.Windows.Forms.MenuItem
036        Private menuItem12 As System.Windows.Forms.MenuItem
037        Private WithEvents mnuPrint As System.Windows.Forms.MenuItem
038        Private WithEvents mnuPageSetUp As System.Windows.Forms.MenuItem
039        Private menuItem9 As System.Windows.Forms.MenuItem
040        Private WithEvents textBox1 As System.Windows.Forms.TextBox
041        Private WithEvents mnuPaste As System.Windows.Forms.MenuItem
042        Private WithEvents mnuCopy As System.Windows.Forms.MenuItem
043        Private mnuEdit As System.Windows.Forms.MenuItem
044        Private WithEvents mnuSaveAs As System.Windows.Forms.MenuItem
045        Private WithEvents mnuSave As System.Windows.Forms.MenuItem
046        Private WithEvents mnuOpen As System.Windows.Forms.MenuItem
047        Private WithEvents mnuNew As System.Windows.Forms.MenuItem
048        Private mnuFile As System.Windows.Forms.MenuItem
049        Private mainMenu1 As System.Windows.Forms.MainMenu
050 
051        Private blnSaveChkFlag As Boolean
052 
053        Public Sub New()
054            InitializeComponent()
055 
056            '
057            textBox1.Width = Me.Width
058            textBox1.Height = Me.Height
059            GetSettings()
060        End Sub
061 
062        Protected Overloads Sub Dispose(ByVal disposing As Boolean)
063            If disposing Then
064                If Not (components Is Nothing) Then
065                    components.Dispose()
066                End If
067            End If
068            MyBase.Dispose(disposing)
069        End Sub
070 
071        Private Sub InitializeComponent()
072            Me.mnuPaste = New System.Windows.Forms.MenuItem
073            Me.mnuSetFontColor = New System.Windows.Forms.MenuItem
074            Me.MnuTimeDate = New System.Windows.Forms.MenuItem
075            Me.colorDialog1 = New System.Windows.Forms.ColorDialog
076            Me.mnuSaveAs = New System.Windows.Forms.MenuItem
077            Me.mnuSetBackCol = New System.Windows.Forms.MenuItem
078            Me.mnuNew = New System.Windows.Forms.MenuItem
079            Me.mnuAbout = New System.Windows.Forms.MenuItem
080            Me.pageSetupDialog1 = New System.Windows.Forms.PageSetupDialog
081            Me.mnuCopy = New System.Windows.Forms.MenuItem
082            Me.mnuExit = New System.Windows.Forms.MenuItem
083            Me.mnuUndo = New System.Windows.Forms.MenuItem
084            Me.menuItem12 = New System.Windows.Forms.MenuItem
085            Me.mnuPrint = New System.Windows.Forms.MenuItem
086            Me.mnuFile = New System.Windows.Forms.MenuItem
087            Me.mnuOpen = New System.Windows.Forms.MenuItem
088            Me.mnuSave = New System.Windows.Forms.MenuItem
089            Me.menuItem9 = New System.Windows.Forms.MenuItem
090            Me.mnuPageSetUp = New System.Windows.Forms.MenuItem
091            Me.mnuWordWrap = New System.Windows.Forms.MenuItem
092            Me.mnuCut = New System.Windows.Forms.MenuItem
093            Me.menuItem7 = New System.Windows.Forms.MenuItem
094            Me.menuItem6 = New System.Windows.Forms.MenuItem
095            Me.mnuSetFont = New System.Windows.Forms.MenuItem
096            Me.mnuSelectAll = New System.Windows.Forms.MenuItem
097            Me.menuItem2 = New System.Windows.Forms.MenuItem
098            Me.menuItem5 = New System.Windows.Forms.MenuItem
099            Me.saveFileDialog1 = New System.Windows.Forms.SaveFileDialog
100            Me.textBox1 = New System.Windows.Forms.TextBox
101            Me.mnuDelete = New System.Windows.Forms.MenuItem
102            Me.mnuEdit = New System.Windows.Forms.MenuItem
103            Me.mainMenu1 = New System.Windows.Forms.MainMenu
104            Me.fontDialog1 = New System.Windows.Forms.FontDialog
105            Me.openFileDialog1 = New System.Windows.Forms.OpenFileDialog
106            Me.printDialog1 = New System.Windows.Forms.PrintDialog
107            Me.SuspendLayout()
108            'hasil generate
109            'mnuPaste
110 
111            Me.mnuPaste.Index = 4
112            Me.mnuPaste.Shortcut = System.Windows.Forms.Shortcut.CtrlV
113            Me.mnuPaste.Text = "&Paste"
114            '
115            'mnuSetFontColor
116            '
117            Me.mnuSetFontColor.Index = 1
118            Me.mnuSetFontColor.Text = "Set Font C&olor..."
119            '
120            'MnuTimeDate
121            '
122            Me.MnuTimeDate.Index = 8
123            Me.MnuTimeDate.Shortcut = System.Windows.Forms.Shortcut.F5
124            Me.MnuTimeDate.Text = "&Time/Date"
125            '
126            'mnuSaveAs
127            '
128            Me.mnuSaveAs.Index = 3
129            Me.mnuSaveAs.Text = "Save &As..."
130            '
131            'mnuSetBackCol
132            '
133            Me.mnuSetBackCol.Index = 2
134            Me.mnuSetBackCol.Text = "Set &Background Color..."
135            '
136            'mnuNew
137            '
138            Me.mnuNew.Index = 0
139            Me.mnuNew.Shortcut = System.Windows.Forms.Shortcut.CtrlN
140            Me.mnuNew.Text = "&New"
141            '
142            'mnuAbout
143            '
144            Me.mnuAbout.Index = 0
145            Me.mnuAbout.Text = "&About"
146            '
147            'mnuCopy
148            '
149            Me.mnuCopy.Index = 3
150            Me.mnuCopy.Shortcut = System.Windows.Forms.Shortcut.CtrlC
151            Me.mnuCopy.Text = "&Copy"
152            '
153            'mnuExit
154            '
155            Me.mnuExit.Index = 8
156            Me.mnuExit.Shortcut = System.Windows.Forms.Shortcut.AltF4
157            Me.mnuExit.Text = "E&xit"
158            '
159            'mnuUndo
160            '
161            Me.mnuUndo.Index = 0
162            Me.mnuUndo.Shortcut = System.Windows.Forms.Shortcut.CtrlZ
163            Me.mnuUndo.Text = "&Undo"
164            '
165            'menuItem12
166            '
167            Me.menuItem12.Index = 7
168            Me.menuItem12.Text = "-"
169            '
170            'mnuPrint
171            '
172            Me.mnuPrint.Index = 6
173            Me.mnuPrint.Shortcut = System.Windows.Forms.Shortcut.CtrlP
174            Me.mnuPrint.Text = "&Print"
175            '
176            'mnuFile
177            '
178            Me.mnuFile.Index = 0
179            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})
180            Me.mnuFile.Text = "&File"
181            '
182            'mnuOpen
183            '
184            Me.mnuOpen.Index = 1
185            Me.mnuOpen.Shortcut = System.Windows.Forms.Shortcut.CtrlO
186            Me.mnuOpen.Text = "&Open..."
187            '
188            'mnuSave
189            '
190            Me.mnuSave.Index = 2
191            Me.mnuSave.Shortcut = System.Windows.Forms.Shortcut.CtrlS
192            Me.mnuSave.Text = "&Save"
193            '
194            'menuItem9
195            '
196            Me.menuItem9.Index = 4
197            Me.menuItem9.Text = "-"
198            '
199            'mnuPageSetUp
200            '
201            Me.mnuPageSetUp.Index = 5
202            Me.mnuPageSetUp.Text = "Page Se&tup..."
203            '
204            'mnuWordWrap
205            '
206            Me.mnuWordWrap.Index = 9
207            Me.mnuWordWrap.Text = "&Word Wrap"
208            '
209            'mnuCut
210            '
211            Me.mnuCut.Index = 2
212            Me.mnuCut.Shortcut = System.Windows.Forms.Shortcut.CtrlX
213            Me.mnuCut.Text = "C&ut"
214            '
215            'menuItem7
216            '
217            Me.menuItem7.Index = 3
218            Me.menuItem7.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuAbout})
219            Me.menuItem7.Text = "&Help"
220            '
221            'menuItem6
222            '
223            Me.menuItem6.Index = 2
224            Me.menuItem6.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuSetFont, Me.mnuSetFontColor, Me.mnuSetBackCol})
225            Me.menuItem6.Text = "&Tools"
226            '
227            'mnuSetFont
228            '
229            Me.mnuSetFont.Index = 0
230            Me.mnuSetFont.Text = "Set &Font..."
231            '
232            'mnuSelectAll
233            '
234            Me.mnuSelectAll.Index = 7
235            Me.mnuSelectAll.Shortcut = System.Windows.Forms.Shortcut.CtrlA
236            Me.mnuSelectAll.Text = "Select &All"
237            '
238            'menuItem2
239            '
240            Me.menuItem2.Index = 1
241            Me.menuItem2.Text = "-"
242            '
243            'menuItem5
244            '
245            Me.menuItem5.Index = 6
246            Me.menuItem5.Text = "-"
247            '
248            'saveFileDialog1
249            '
250            Me.saveFileDialog1.CheckFileExists = True
251            Me.saveFileDialog1.DefaultExt = "txt"
252            Me.saveFileDialog1.FileName = "doc1"
253            Me.saveFileDialog1.Filter = "Text files (*.txt)|*.txt"
254            Me.saveFileDialog1.RestoreDirectory = True
255            '
256            'textBox1
257            '
258            Me.textBox1.AutoSize = False
259            Me.textBox1.Location = New System.Drawing.Point(0, 0)
260            Me.textBox1.Multiline = True
261            Me.textBox1.Name = "textBox1"
262            Me.textBox1.Size = New System.Drawing.Size(440, 304)
263            Me.textBox1.TabIndex = 0
264            Me.textBox1.Text = ""
265            '
266            'mnuDelete
267            '
268            Me.mnuDelete.Index = 5
269            Me.mnuDelete.Shortcut = System.Windows.Forms.Shortcut.Del
270            Me.mnuDelete.Text = "De&lete"
271            '
272            'mnuEdit
273            '
274            Me.mnuEdit.Index = 1
275            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})
276            Me.mnuEdit.Text = "&Edit"
277            '
278            'mainMenu1
279            '
280            Me.mainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuFile, Me.mnuEdit, Me.menuItem6, Me.menuItem7})
281            '
282            'openFileDialog1
283            '
284            Me.openFileDialog1.DefaultExt = "*.txt"
285            Me.openFileDialog1.Filter = "Text files (*.txt)|*.txt"
286            Me.openFileDialog1.RestoreDirectory = True
287            Me.openFileDialog1.Title = "Open File"
288            '
289            'Form1
290            '
291            Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
292            Me.ClientSize = New System.Drawing.Size(576, 377)
293            Me.Controls.Add(Me.textBox1)
294            Me.Menu = Me.mainMenu1
295            Me.Name = "Form1"
296            Me.Text = "NotePad Bahrie"
297            Me.ResumeLayout(False)
298 
299        End Sub 'InitializeComponent
300 
301        Protected Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
302            textBox1.Width = Me.Width
303            textBox1.Height = Me.Height
304        End Sub 'supaya ukuran tampilannya flaksibel
305 
306        Protected Sub mnuAbout_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuAbout.Click
307            Dim abt = New about
308            abt.ShowDialog()
309        End Sub 'menu abaut.
310 
311        Protected Sub mnuSetBackCol_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuSetBackCol.Click
312            colorDialog1.ShowDialog()
313            textBox1.BackColor = colorDialog1.Color
314        End Sub
315 
316        Protected Sub mnuFontColor_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuSetFontColor.Click
317            colorDialog1.ShowDialog()
318            textBox1.ForeColor = colorDialog1.Color
319        End Sub
320 
321        Protected Sub mnuSetFont_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuSetFont.Click
322            fontDialog1.ShowDialog()
323            textBox1.Font = fontDialog1.Font
324        End Sub
325 
326        Protected Sub mnuWordWrap_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuWordWrap.Click
327            textBox1.WordWrap = Not textBox1.WordWrap
328            mnuWordWrap.Checked = Not mnuWordWrap.Checked
329        End Sub
330 
331        Protected Sub MnuTimeDate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MnuTimeDate.Click
332            textBox1.Text = textBox1.Text + DateTime.Now.ToLongTimeString() + DateTime.Now.ToLongDateString()
333            textBox1.SelectionLength = textBox1.Text.Length
334            textBox1.SelectionStart = textBox1.Text.Length
335        End Sub
336 
337        Protected Sub mnuSelectAll_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuSelectAll.Click
338            textBox1.SelectAll()
339        End Sub
340 
341        Protected Sub mnuDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuDelete.Click
342            textBox1.SelectedText = ""
343        End Sub
344 
345        Protected Sub mnuCut_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuCut.Click
346            textBox1.Cut()
347        End Sub
348 
349        Protected Sub mnuUndo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuUndo.Click
350            textBox1.Undo()
351        End Sub
352 
353        Protected Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
354            'ngecek saat diklose
355            If checkUnSavedData() = False Then
356                e.Cancel = True
357                Return
358            End If
359            SaveSettings() 'Save setting ke registry
360        End Sub '
361 
362        Protected Sub textBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles textBox1.TextChanged
363            blnSaveChkFlag = True
364        End Sub
365 
366        Protected Sub mnuPrint_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuPrint.Click
367 
368            printDialog1.AllowPrintToFile = True
369            Dim docPrn As New PrintDocument
370            docPrn.DocumentName = textBox1.Text
371            printDialog1.Document = docPrn
372            If printDialog1.ShowDialog() = DialogResult.OK Then
373                Try
374                    docPrn.Print()
375                Catch
376                End Try
377            End If
378        End Sub
379 
380        Protected Sub mnuPageSetUp_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuPageSetUp.Click
381            Dim docPrn As New PrintDocument
382            docPrn.DocumentName = textBox1.Text
383            pageSetupDialog1.Document = docPrn
384            pageSetupDialog1.ShowDialog()
385        End Sub
386 
387        Protected Sub mnuSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuSave.Click
388            SaveFile()
389        End Sub
390 
391        Protected Sub mnuExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuExit.Click
392 
393            If checkUnSavedData() Then
394                Me.Close()
395            End If
396        End Sub
397 
398        Private Function SaveFile() As Boolean
399            Try
400                Dim fName As String
401                Dim dlgR As DialogResult = saveFileDialog1.ShowDialog()
402                If dlgR = DialogResult.Cancel Then
403 
404                    blnSaveChkFlag = True
405                    Return False
406                End If
407                fName = saveFileDialog1.FileName
408                Dim fSave As New StreamWriter(fName)
409                fSave.WriteLine(textBox1.Text)
410                fSave.Flush()
411                fSave.Close()
412                Me.Text = fName
413                blnSaveChkFlag = False
414                Return True
415            Catch
416            End Try
417        End Function
418 
419        Protected Sub mnuSaveAs_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuSaveAs.Click
420 
421            SaveFile()
422        End Sub
423 
424        Protected Sub mnuOpen_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuOpen.Click
425            If checkUnSavedData() Then
426                openFileDialog1.ShowDialog()
427                Try
428                    If File.Exists(openFileDialog1.FileName) Then
429                        Dim o As StreamReader = File.OpenText(openFileDialog1.FileName)
430                        textBox1.Text = o.ReadToEnd()
431                    End If
432                    textBox1.SelectionStart = 0
433                    textBox1.SelectionLength = 0
434                    blnSaveChkFlag = False
435                Catch
436                End Try
437            End If
438        End Sub
439 
440        Protected Sub mnuPaste_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuPaste.Click
441 
442            Dim iData As IDataObject = Clipboard.GetDataObject()
443 
444            If iData.GetDataPresent(DataFormats.Text) Then
445                textBox1.SelectedText = CType(iData.GetData(DataFormats.Text), [String])
446            End If
447        End Sub
448 
449        Protected Sub mnuCopy_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuCopy.Click
450            Clipboard.SetDataObject(textBox1.SelectedText, True)
451        End Sub
452 
453        Private Function checkUnSavedData() As Boolean
454            If blnSaveChkFlag = True Then
455                Dim dlgRes As DialogResult
456                dlgRes = MessageBox.Show("File akan mengalami perubahan, Simpan apa tidak ??", "NotePad_Bahrie", MessageBoxButtons.YesNoCancel)
457 
458                Select Case dlgRes
459                    Case DialogResult.Yes
460 
461                        Return SaveFile()
462                    Case DialogResult.No
463                        blnSaveChkFlag = False
464                        Return True
465                    Case DialogResult.Cancel
466                        Return False
467                End Select
468            End If
469            Return True
470        End Function
471 
472        Protected Sub mnuNew_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuNew.Click
473 
474            If checkUnSavedData() Then
475                textBox1.Clear() 'sama aja dengan textBox1.Text="";
476                blnSaveChkFlag = False
477                Me.Text = "Untitled - NotePad Bahrie"
478            End If
479        End Sub
480 
481        Private Sub SaveSettings()
482 
483            Try
484 
485                Dim reKSubKey As RegistryKey = Registry.LocalMachine
486                reKSubKey.CreateSubKey("Bahrie")
487 
488                reKSubKey.SetValue("FontName", textBox1.Font.FontFamily.GetName(0))
489                reKSubKey.SetValue("FontSize", Convert.ToString(textBox1.Font.Size))
490 
491                reKSubKey.SetValue("ForeCol", Convert.ToString(textBox1.ForeColor.ToArgb()))
492 
493                reKSubKey.SetValue("BackCol", Convert.ToString(textBox1.BackColor.ToArgb()))
494            Catch
495            End Try
496        End Sub
497 
498        Private Sub GetSettings()
499 
500            Try
501                Dim reK As RegistryKey = Registry.LocalMachine
502                reK.OpenSubKey("Bahrie")
503 
504                textBox1.Font = New System.Drawing.Font(reK.GetValue("FontName").ToString(), Convert.ToSingle(reK.GetValue("FontSize")))
505                textBox1.ForeColor = System.Drawing.Color.FromArgb(Convert.ToInt32(reK.GetValue("ForeCol")))
506                textBox1.BackColor = System.Drawing.Color.FromArgb(Convert.ToInt32(reK.GetValue("BackCol")))
507            Catch
508            End Try
509        End Sub
510 
511        Public Overloads Shared Sub Main(ByVal args() As String)
512            Application.Run(New Form1)
513        End Sub 'Main
514 
515    End Class
516End Namespace
dan inilah gambaran hasilnya :




sourcecode dapat anda

 Sumber :http://bahrie27.wordpress.com/2010/04/17/notepad-dengan-vb-net-2003/http://bahrie27.wordpress.com/2010/04/17/notepad-dengan-vb-net-2003/

Tidak ada komentar:

Posting Komentar