简体   繁体   中英

C# - RichTextBoxPrintCtrl and tabcontrol

Hello (and sorry for my English), I have a problem with Printing RTF using RichTextBoxPrintCtrl and TabControl.

1) The tabcontrol got no tabs on Design, when the Form Load, it will get a tab with the method AddTab(Title) . (Don't mind about other variables).

private void AddTab(string Name = "Nuova Nota*")
{
    RichTextBox Body = new RichTextBox();
    Body.Name = "Body";
    Body.Dock = DockStyle.Fill;
    Body.ContextMenuStrip = contextMenuStrip1;
    TabPage NewPage = new TabPage();
    string DocumentText = Nome;
    if (Nome == "Nuova Nota*")
    {
        TabCount += 1;
        DocumentText = Nome + TabCount;
    }
    NewPage.Name = DocumentText;
    NewPage.Text = DocumentText;
    tabControl1.Visible = true;
    NewPage.Controls.Add(Body);
    tabControl1.TabPages.Add(NewPage);
    tabControl1.SelectedTab = NewPage;
    Nomi_Files.Add(NewPage.Text);
    Path_Files.Add("");
}

2) Once the tab is created, you can start to write, change colors, fonts, etc... To get access on the document that you are making, i use a GetCurrentDocument that return the "Body" of the selected tab:

private RichTextBox GetCurrentDocument
{
    get { return (RichTextBox)tabControl1.SelectedTab.Controls["Body"];}
}

Now, all the functions (save, open, fonts, colors...) Works Fine, i wanted to print my document and keep the style, so i Googled and i found this: How to print the content of a RichTextBox control by using Visual C#

I made the RichTextBoxPrintCtrl.dll , added the resource on my project, added the item inside the toolbox, but i can't change the RichTextBox that i create from Code, with RichTextBoxPrintCtrl . The error that i get is:

Error 1 'RichTextBoxPrintCtrl' is a 'namespace' but is used like a 'type'

How i can use that RichTextBoxPrintCtrl without drag and drop it inside the design form?

Ok, i figured out how to solve it:

instead of declaring like:

RichTextBoxPrintCtrl NameControl = new RichTextBoxPrintCtrl(); 

we need to declare the namespace so:

RichTextBoxPrintCtrl.RichTextBoxPrintCtrl NameControl = new RichTextBoxPrintCtrl.RichTextBoxPrintCtrl();

Everything works fine :) thanks;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM