I am trying to learn VC sharp and I am trying to write a tabbed notepad, very simple i know but its a start.
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)
{
}
}