- Goto Toolbox and drag and drop a TabControl
- We need a plain tabb. Because right click on middle of the tabb and select Delete
- Delete default two tabbs
- Click on tabb and go to Propeties -> Dock -> Fill
- Double click on the New submenu and enter this codes
TabPage tp = new TabPage("New"); RichTextBox rtb = new RichTextBox(); rtb.Dock = DockStyle.Fill; tp.Controls.Add(rtb); tabControl1.TabPages.Add(tp); - You have to make a new function for text box. here we are using RichTextbox
- This is code for it
- Double click on the submenu item and enter following codes
- Open
OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Text File(*.txt)|*.txt"; if (ofd.ShowDialog() == DialogResult.OK) { System.IO.StreamReader sr = new System.IO.StreamReader(ofd.FileName); GetRichBox().Text = sr.ReadToEnd(); sr.Close(); }- Save
SaveFileDialog sfd = new SaveFileDialog(); if (sfd.ShowDialog() == DialogResult.OK) { System.IO.StreamWriter sw = new System.IO.StreamWriter(sfd.FileName); sw.Write(GetRichBox().Text); sw.Close(); }- Exit
Application.Exit();- Undo
GetRichBox().Undo();
- Redo
GetRichBox().Redo();
- Cut
GetRichBox().Cut();
- Copy
GetRichBox().Copy();
- Paste
GetRichBox().Paste();
- Select All
GetRichBox().selectAll();
- We can add a filter when open and save a text file.
- To do this add following code to Open and Save submenus
- Open
ofd.Filter="Text File(*.txt)|*.txt";- Save
sfd.Filter="Text Files(*.txt)|*.txt";
private RichTextBox GetRichBox()
{
RichTextBox rtb = null;
TabPage tp = tabControl1.SelectedTab;
if(tp!=null)
{
rtb = tp.Controls[0] as RichTextBox;
}
return rtb;
}
Now let's code the othersNext post I will show you how search a word and highlight them






No comments:
Post a Comment