6 Months Free & No Setup Fees ASP.NET Hosting!
Skip Navigation Links
C# Corner Home
Forum Home
Latest 50
Unanswered
Win Prizes
All Time Leaders
Jump to CategoryExpand Jump to Category
Login 
    Welcome Guest!
 Search Forum For :  
X
 Login
Please login to submit a new post, reply and edit exiting posts, see user profiles, and access more features. If you are not a registered member, Register here.
User Id / Email:
Password:  
Forgot Password | Forgot UserName
   Home » Windows Azure » Tabbed Notepad
       
Author Reply
My name
posted 9 posts
since Jan 25, 2006 
from

Tabbed Notepad

  Posted on: 04 Feb 2012       
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)
        {

        }
               

          }
Frogleg
posted  831 posts
since  Aug 13, 2010 
from  Australia

 Re: Tabbed Notepad
  Posted on: 04 Feb 2012        0  
Try this

int index = tabControl1.TabIndex;
tabControl1.TabPages.RemoveAt(index);
My name
posted  9 posts
since  Jan 25, 2006 
from 

 Re: Tabbed Notepad
  Posted on: 04 Feb 2012        0  
Thanks.  The problem is that I dont know how to create a Context Menu for this, and then assign it to the right click on a Tab

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

Frogleg
posted  831 posts
since  Aug 13, 2010 
from  Australia

 Re: Tabbed Notepad
  Posted on: 04 Feb 2012   Accepted Answer     0  
From toolbox - drag contextmenu onto form
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
My name
posted  9 posts
since  Jan 25, 2006 
from 

 Re: Tabbed Notepad
  Posted on: 04 Feb 2012        0  
Awesome .. thanks taht works..


My name
posted  9 posts
since  Jan 25, 2006 
from 

 Re: Tabbed Notepad
  Posted on: 05 Feb 2012        0  
I have one other question,  and have some issues. 

I  am trying top open and save files and have tried something but seem to have issues. 

WHat am I am doing wrong 

private void openToolStripButton_Click(object sender, EventArgs e)
        {
            OpenFileDialog OpenFileDialog1 = new OpenFileDialog();
            string AllText = "";
            string LineOfText = "";
            //This bottom code is telling it to search each and ever file type
            OpenFileDialog1.Filter = "All Files|*.*";
            //This bottom code basically shows the opendialog box
            OpenFileDialog1.ShowDialog();
            try
            {
                FileSytem.FileOpen(1, OpenFileDialog1.FileName, OpenMode.Input);
                while (!(FileSystem.EOF(1)))
                {
                    LineOfText = FileSystem.LineInput(1);
                    AllText = AllText + LineOfText + Constants.vbCrLf;
                }
                ((RichTextBox)TabControl1.SelectedTab.Controls.Item(0)).Text = AllText;
            }
            catch
            {
            }
            finally
            {
                FileSystem.FileClose(1);
            }


The Save Code is like this 



            SaveFileDialog SaveFileDialog1 = new SaveFileDialog();

            SaveFileDialog1.Filter(" Rich Text Files|*.rtf|Text Files|*.txt");
            //Shows the file Dialog

            SaveFileDialog1.ShowDialog();
            FileSystem.FileOpen(1, SaveFileDialog1.FileName, OpenMode.Output);
            FileSystem.PrintLine(1, ((RichTextBox)TabControl1.SelectTab.Controls.Item(0)).Text);
            FileSystem.FileClose(1);


Any help is appreciated 




Sam Hobbs
posted  6490 posts
since  Sep 07, 2009 
from  Los Angeles, California, USA

 Re: Tabbed Notepad
  Posted on: 05 Feb 2012        0  
Chris, you should mark Frogleg's answer as the answer and then create a new thread for the new question. When you creater a new thread for your new question, please explain what the problem is; I don't see anything saying that there is an error message or anything.

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.
Thinking is a feeling; pleasant for some and unpleasant for others.
       
6 Months Free & No Setup Fees ASP.NET Hosting!
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
6 Months Free & No Setup Fees ASP.NET Hosting!
 Hosted by MaximumASP  |  Found a broken link?  |  Contact Us  |  Terms & conditions  |  Privacy Policy  |  Site Map  |  Advertise with us
Current Version: 5.2011.3.12
 © 1999 - 2012  Mindcracker LLC. All Rights Reserved