ini merupakan tugas matakuliah pemrograman vb.net 2003. ini tampilan di dalam form vb.net
lihat apa saja pallete yang dibutuhkan..
inilah sourcecodenya..
002 | Imports System.Drawing |
003 | Imports System.Collections |
004 | Imports System.ComponentModel |
005 | Imports System.Windows.Forms |
008 | Imports System.Drawing.Printing |
009 | Imports Microsoft.Win32 |
011 | Namespace NotePadeBahrie |
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 |
051 | Private blnSaveChkFlag As Boolean |
054 | InitializeComponent() |
057 | textBox1.Width = Me.Width |
058 | textBox1.Height = Me.Height |
062 | Protected Overloads Sub Dispose(ByVal disposing As Boolean) |
064 | If Not (components Is Nothing) Then |
068 | MyBase.Dispose(disposing) |
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 |
111 | Me.mnuPaste.Index = 4 |
112 | Me.mnuPaste.Shortcut = System.Windows.Forms.Shortcut.CtrlV |
113 | Me.mnuPaste.Text = "&Paste" |
117 | Me.mnuSetFontColor.Index = 1 |
118 | Me.mnuSetFontColor.Text = "Set Font C&olor..." |
122 | Me.MnuTimeDate.Index = 8 |
123 | Me.MnuTimeDate.Shortcut = System.Windows.Forms.Shortcut.F5 |
124 | Me.MnuTimeDate.Text = "&Time/Date" |
128 | Me.mnuSaveAs.Index = 3 |
129 | Me.mnuSaveAs.Text = "Save &As..." |
133 | Me.mnuSetBackCol.Index = 2 |
134 | Me.mnuSetBackCol.Text = "Set &Background Color..." |
139 | Me.mnuNew.Shortcut = System.Windows.Forms.Shortcut.CtrlN |
140 | Me.mnuNew.Text = "&New" |
144 | Me.mnuAbout.Index = 0 |
145 | Me.mnuAbout.Text = "&About" |
150 | Me.mnuCopy.Shortcut = System.Windows.Forms.Shortcut.CtrlC |
151 | Me.mnuCopy.Text = "&Copy" |
156 | Me.mnuExit.Shortcut = System.Windows.Forms.Shortcut.AltF4 |
157 | Me.mnuExit.Text = "E&xit" |
162 | Me.mnuUndo.Shortcut = System.Windows.Forms.Shortcut.CtrlZ |
163 | Me.mnuUndo.Text = "&Undo" |
167 | Me.menuItem12.Index = 7 |
168 | Me.menuItem12.Text = "-" |
172 | Me.mnuPrint.Index = 6 |
173 | Me.mnuPrint.Shortcut = System.Windows.Forms.Shortcut.CtrlP |
174 | Me.mnuPrint.Text = "&Print" |
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" |
185 | Me.mnuOpen.Shortcut = System.Windows.Forms.Shortcut.CtrlO |
186 | Me.mnuOpen.Text = "&Open..." |
191 | Me.mnuSave.Shortcut = System.Windows.Forms.Shortcut.CtrlS |
192 | Me.mnuSave.Text = "&Save" |
196 | Me.menuItem9.Index = 4 |
197 | Me.menuItem9.Text = "-" |
201 | Me.mnuPageSetUp.Index = 5 |
202 | Me.mnuPageSetUp.Text = "Page Se&tup..." |
206 | Me.mnuWordWrap.Index = 9 |
207 | Me.mnuWordWrap.Text = "&Word Wrap" |
212 | Me.mnuCut.Shortcut = System.Windows.Forms.Shortcut.CtrlX |
213 | Me.mnuCut.Text = "C&ut" |
217 | Me.menuItem7.Index = 3 |
218 | Me.menuItem7.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuAbout}) |
219 | Me.menuItem7.Text = "&Help" |
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" |
229 | Me.mnuSetFont.Index = 0 |
230 | Me.mnuSetFont.Text = "Set &Font..." |
234 | Me.mnuSelectAll.Index = 7 |
235 | Me.mnuSelectAll.Shortcut = System.Windows.Forms.Shortcut.CtrlA |
236 | Me.mnuSelectAll.Text = "Select &All" |
240 | Me.menuItem2.Index = 1 |
241 | Me.menuItem2.Text = "-" |
245 | Me.menuItem5.Index = 6 |
246 | Me.menuItem5.Text = "-" |
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 |
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 = "" |
268 | Me.mnuDelete.Index = 5 |
269 | Me.mnuDelete.Shortcut = System.Windows.Forms.Shortcut.Del |
270 | Me.mnuDelete.Text = "De&lete" |
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" |
280 | Me.mainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuFile, Me.mnuEdit, Me.menuItem6, Me.menuItem7}) |
284 | Me.openFileDialog1.DefaultExt = "*.txt" |
285 | Me.openFileDialog1.Filter = "Text files (*.txt)|*.txt" |
286 | Me.openFileDialog1.RestoreDirectory = True |
287 | Me.openFileDialog1.Title = "Open File" |
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 |
296 | Me.Text = "NotePad Bahrie" |
297 | Me.ResumeLayout(False) |
299 | End Sub 'InitializeComponent |
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 |
306 | Protected Sub mnuAbout_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuAbout.Click |
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 |
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 |
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 |
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 |
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 |
337 | Protected Sub mnuSelectAll_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuSelectAll.Click |
341 | Protected Sub mnuDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuDelete.Click |
342 | textBox1.SelectedText = "" |
345 | Protected Sub mnuCut_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuCut.Click |
349 | Protected Sub mnuUndo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuUndo.Click |
353 | Protected Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing |
355 | If checkUnSavedData() = False Then |
359 | SaveSettings() 'Save setting ke registry |
362 | Protected Sub textBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles textBox1.TextChanged |
363 | blnSaveChkFlag = True |
366 | Protected Sub mnuPrint_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuPrint.Click |
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 |
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() |
387 | Protected Sub mnuSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuSave.Click |
391 | Protected Sub mnuExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuExit.Click |
393 | If checkUnSavedData() Then |
398 | Private Function SaveFile() As Boolean |
401 | Dim dlgR As DialogResult = saveFileDialog1.ShowDialog() |
402 | If dlgR = DialogResult.Cancel Then |
404 | blnSaveChkFlag = True |
407 | fName = saveFileDialog1.FileName |
408 | Dim fSave As New StreamWriter(fName) |
409 | fSave.WriteLine(textBox1.Text) |
413 | blnSaveChkFlag = False |
419 | Protected Sub mnuSaveAs_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuSaveAs.Click |
424 | Protected Sub mnuOpen_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuOpen.Click |
425 | If checkUnSavedData() Then |
426 | openFileDialog1.ShowDialog() |
428 | If File.Exists(openFileDialog1.FileName) Then |
429 | Dim o As StreamReader = File.OpenText(openFileDialog1.FileName) |
430 | textBox1.Text = o.ReadToEnd() |
432 | textBox1.SelectionStart = 0 |
433 | textBox1.SelectionLength = 0 |
434 | blnSaveChkFlag = False |
440 | Protected Sub mnuPaste_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuPaste.Click |
442 | Dim iData As IDataObject = Clipboard.GetDataObject() |
444 | If iData.GetDataPresent(DataFormats.Text) Then |
445 | textBox1.SelectedText = CType(iData.GetData(DataFormats.Text), [String]) |
449 | Protected Sub mnuCopy_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuCopy.Click |
450 | Clipboard.SetDataObject(textBox1.SelectedText, True) |
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) |
459 | Case DialogResult.Yes |
463 | blnSaveChkFlag = False |
465 | Case DialogResult.Cancel |
472 | Protected Sub mnuNew_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuNew.Click |
474 | If checkUnSavedData() Then |
475 | textBox1.Clear() 'sama aja dengan textBox1.Text=""; |
476 | blnSaveChkFlag = False |
477 | Me.Text = "Untitled - NotePad Bahrie" |
481 | Private Sub SaveSettings() |
485 | Dim reKSubKey As RegistryKey = Registry.LocalMachine |
486 | reKSubKey.CreateSubKey("Bahrie") |
488 | reKSubKey.SetValue("FontName", textBox1.Font.FontFamily.GetName(0)) |
489 | reKSubKey.SetValue("FontSize", Convert.ToString(textBox1.Font.Size)) |
491 | reKSubKey.SetValue("ForeCol", Convert.ToString(textBox1.ForeColor.ToArgb())) |
493 | reKSubKey.SetValue("BackCol", Convert.ToString(textBox1.BackColor.ToArgb())) |
498 | Private Sub GetSettings() |
501 | Dim reK As RegistryKey = Registry.LocalMachine |
502 | reK.OpenSubKey("Bahrie") |
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"))) |
511 | Public Overloads Shared Sub Main(ByVal args() As String) |
512 | Application.Run(New Form1) |
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