Anyway I have the basics of it so will create a new tab when clicking on new.
I am looking for a way to close a tab by right clicking on it and selecting close from a context menu.. Can someone let me know how I would do this.
Thanks
here is the code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
NewTab();
}
private RichTextBox GetRichTextBox()
{
RichTextBox rtb = null;
TabPage tp = tabControl1.SelectedTab;
if (tp != null) //If a tab is selected
{
rtb = tp.Controls[0] as RichTextBox;
}
return rtb;
}
public void NewTab()
{
if (tabControl1.TabPages.Count != 100) // Count the amount of Tabs
{
// This Subroutine will create a new Tab and RichTextBox
TabPage tp = new TabPage("untitled.txt");
RichTextBox rtb = new RichTextBox();
rtb.Dock = DockStyle.Fill;
tp.Controls.Add(rtb);
tabControl1.TabPages.Add(tp);
}
else
{
MessageBox.Show("You have reached the limit on tabs.");
}
}
private void newToolStripMenuItem_Click(object sender, EventArgs e)
{
NewTab();
}
private void newToolStripButton_Click(object sender, EventArgs e)
{
NewTab();
}
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void cutToolStripMenuItem_Click(object sender, EventArgs e)
{
GetRichTextBox().Cut();
}
private void copyToolStripMenuItem_Click(object sender, EventArgs e)
{
GetRichTextBox().Copy();
}
private void pasteToolStripMenuItem_Click(object sender, EventArgs e)
{
GetRichTextBox().Paste();
}
private void selectAllToolStripMenuItem_Click(object sender, EventArgs e)
{
GetRichTextBox().SelectAll();
}
private void undoToolStripMenuItem_Click(object sender, EventArgs e)
{
GetRichTextBox().Undo();
}
private void cutToolStripButton_Click(object sender, EventArgs e)
{
GetRichTextBox().Cut();
}
private void copyToolStripButton_Click(object sender, EventArgs e)
{
GetRichTextBox().Copy();
}
private void pasteToolStripButton_Click(object sender, EventArgs e)
{
GetRichTextBox().Paste();
}
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
}
}
FroglegPosted Feb 4, 2012, 5:29 PM
In context menu properties, go to collections and then add a new menu item
On the form you will see the menuitem so click on it as with any other button to write code
Finally, in tabcontrol1 properties, look for contextmenu, click in righthand pane and select contextmenu1
Sam HobbsPosted Feb 5, 2012, 8:40 PM
Also, have a look at the articles in this web site; I think there is an article with a sample of a tabbed text editor.
My name 0Posted Feb 5, 2012, 4:12 PM
I am trying top open and save files and have tried something but seem to have issues.
WHat am I am doing wrong
The Save Code is like this
Any help is appreciated
My name 0Posted Feb 4, 2012, 5:50 PM
My name 0Posted Feb 4, 2012, 5:17 PM
i.e when I run the program, I want to right click on a TAb and then it will bring a context menu and allow me to close the tab
FroglegPosted Feb 4, 2012, 5:06 PM
int index = tabControl1.TabIndex;
tabControl1.TabPages.RemoveAt(index);