Beispiel #1
0
        private void btNew_Click(object sender, EventArgs e)
        {
            int    newTabIndex = 1;
            string newTabName  = "new 1";

            for (int i = 0; i < tabControl.TabPages.Count; i++)
            {
                string tabName = tabControl.TabPages[i].Text;

                if (tabName == newTabName)
                {
                    newTabIndex++;
                    newTabName = "new " + newTabIndex.ToString();

                    //Start over the loop
                    i = -1;
                }
            }

            TabControlMethods.CreateNewTabPage(newTabName);

            //Set the current highlight language for new tab
            string currentLanguage = "";

            foreach (var item in languageToolStripMenuItem.DropDownItems)
            {
                if (((ToolStripMenuItem)item).Checked == true)
                {
                    currentLanguage = ((ToolStripMenuItem)item).Text;
                }
            }
            SetHighlightRule(currentLanguage);

            TabControlMethods.CurrentTextArea.Focus();
        }
Beispiel #2
0
        public static void ShowOpenDialog(TabControl tabControl)
        {
            //create a new file dialog and choose file to open
            OpenFileDialog openDialog = new OpenFileDialog();

            openDialog.Filter = "txt Files (*txt)|*txt|All Files (*.*)|*.*";

            if (openDialog.ShowDialog() == DialogResult.OK)
            {
                //check to see if there is already this tab page
                TabPage currentTabPage = null;
                foreach (TabPage tabPage in tabControl.TabPages)
                {
                    if (tabPage.Name == openDialog.FileName)
                    {
                        currentTabPage = tabPage;
                        break;
                    }
                }

                //Create a new tab page
                TabPage newTabPage = TabControlMethods.CreateNewTabPage(openDialog.SafeFileName);

                //a variable to hold text box contained in tab page
                TypingArea newTypingArea = TabControlMethods.CurrentTextArea;

                //Get the path of the File
                string filePath = openDialog.FileName;

                //Get the text of the file
                string fileText = File.ReadAllText(filePath);

                //Set the text of current text box by file Text
                newTypingArea.Text = fileText;

                //In the next time, if this tab page already has a name, just open it
                tabControl.SelectedTab.Name = openDialog.FileName;
            }
            //dispose for sure
            openDialog.Dispose();
        }