How To Create Notepad Using Form?

crystaluz

Well-known member
Joined
Feb 17, 2009
Messages
55
Programming Experience
Beginner
How to create notepad using form? And its functions same like Windows Notepad?
Thank you...:eek:
 

pasensyoso_manigbas

Well-known member
Joined
May 19, 2006
Messages
64
Programming Experience
Beginner
Do you intend to create an exact copy of notepad or you would just like to use notepad in your form?

You can call the "notepad.exe" if so you like to use it in your form.
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,604
Location
Norway
Programming Experience
10+
Add these to form from Toolbox: TextBox, FontDialog, MenuStrip, OpenFileDialog, SaveFileDialog
Configure Textbox: Multiline (True), Dock (Fill)
Add items to menu (MenuStrip has "Insert Standard Items" functionality that is helpful) and code functionality for these, for example the "Font..." menu choice:
VB.NET:
If Me.FontDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
    Me.TextBox1.Font = Me.FontDialog1.Font
End If
The "Wordwrap" choice:
VB.NET:
Me.TextBox1.WordWrap = Not Me.TextBox1.WordWrap
The File "Open..." choice:
VB.NET:
If Me.OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
    Me.TextBox1.Text = My.Computer.FileSystem.ReadAllText(Me.OpenFileDialog1.FileName)
End If
The File "Save..." choice:
VB.NET:
If Me.SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
    My.Computer.FileSystem.WriteAllText(Me.SaveFileDialog1.FileName, Me.TextBox1.Text, False)
End If
TextBox class has Undo, SelectAll, Cut, Copy and Paste methods, to be used with the menu edit options. Context menu with editing options and editing keyboard shortcuts comes for free with the Textbox.

Insert date/time?
VB.NET:
Me.TextBox1.SelectedText = Date.Now.ToString

Printing is a bit more complex, some preparations is needed. First add a PrintDialog and a PageSetupdialog to form. You also need a PrintDocument, I'd use the inherited TextPrint class posted at A .NET Text Printing Class... That Works!, add the class to project. Sadly this class is missing a parameterless constructor so you have to add one too:
VB.NET:
Public Sub New()
End Sub
Then you can recompile and the TextPrint component will then display in Toolbox, add one of those also to the form. Configure the Document properties for the PrintDialog and PageSetupdialog by selecting the TextPrint1 printdocument instance. Then the code for the File "Print..." option:
VB.NET:
If Me.PrintDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
    Me.TextPrint1.Text = Me.TextBox1.Text
    Me.TextPrint1.Print()
End If
Page setup menu choice just need this code:
VB.NET:
Me.PageSetupDialog1.ShowDialog()
Notepad doesn't have print preview, but you can easily add this also, add a PrintPreviewDialog to form and set Document property to the TextPrint1 instance, then this code for the menu item:
VB.NET:
Me.TextPrint1.Text = Me.TextBox1.Text
Me.PrintPreviewDialog1.ShowDialog()
That should be about it basically.

I didn't see until now that your forum profile states VB 2003, but I think all of this is also available for you. Edit: I know VB 2003 doesn't have MenuStrip, it was new in VB 2005, but it has something called MainMenu that can be used instead.
 

crystaluz

Well-known member
Joined
Feb 17, 2009
Messages
55
Programming Experience
Beginner
JohnH,
I have tried that codes in VB.NeT 2003, all worked except all that related to My.Computer.FileSystem....

The VB.NEt cannot identified the word 'My'
It said that word need to be declared.
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,604
Location
Norway
Programming Experience
10+

crystaluz

Well-known member
Joined
Feb 17, 2009
Messages
55
Programming Experience
Beginner

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,604
Location
Norway
Programming Experience
10+
Use IndexOf method of String (the Text) to find/next, use Select method of Textbox to select the text, use SelectedText property to replace selected text.
 
Top Bottom