0

这是我打开新文件的代码:

private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
    OpenFileDialog openFD = new OpenFileDialog();
    string Chosen_File = "";

    openFD.InitialDirectory = "C:";
    openFD.Title = "Open a Text File";
    openFD.FileName = "";

    openFD.Filter = "Text Files|*.txt|Word Documents|*.doc";

    if (openFD.ShowDialog() != DialogResult.Cancel)
    {

        Chosen_File = openFD.FileName;
        GetRichTextBox().LoadFile(Chosen_File, RichTextBoxStreamType.PlainText);

    }

我也在使用标签。我只能在打开选项卡时打开文件。如何将其设置为使用该文件打开一个新选项卡?它仅在我打开选项卡然后打开文件时才有效。

4

1 回答 1

1

您必须在加载前的文件中添加新TabPageTabControl(代码中的方式):

TabPage tab = new TabPage(){Text = System.IO.Path.GetFileName(Chosen_File)};
tabControl1.TabPages.Add(tab);
tabControl1.SelectedTab = tab;
RichTextBox rich = new RichTextBox{Parent = tab, Dock = DockStyle.Fill};
rich.LoadFile(Chosen_File, RichTextBoxStreamType.PlainText);
于 2013-08-23T20:40:46.683 回答