简体   繁体   English

C#-RichTextBoxPrintCtrl和tabcontrol

[英]C# - RichTextBoxPrintCtrl and tabcontrol

Hello (and sorry for my English), I have a problem with Printing RTF using RichTextBoxPrintCtrl and TabControl. 您好(对不起我的英语),我在使用RichTextBoxPrintCtrl和TabControl打印RTF时遇到问题。

1) The tabcontrol got no tabs on Design, when the Form Load, it will get a tab with the method AddTab(Title) . 1)tabcontrol在设计上没有选项卡,在“窗体加载”时,将使用方法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: 2)一旦创建了选项卡,就可以开始编写,更改颜色,字体等。要访问正在制作的文档,我使用GetCurrentDocument来返回所选选项卡的“正文”:

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# 现在,所有功能(保存,打开,字体,颜色...)都可以正常工作,我想打印文档并保留样式,因此我在Googled上找到了: 如何使用来打印RichTextBox控件的内容可视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 . 我制作了RichTextBoxPrintCtrl.dll ,在项目中添加了资源,在工具箱中添加了该项目,但是我无法使用RichTextBox更改我从Code创建的RichTextBoxPrintCtrl The error that i get is: 我得到的错误是:

Error 1 'RichTextBoxPrintCtrl' is a 'namespace' but is used like a 'type' 错误1'RichTextBoxPrintCtrl'是'命名空间',但像'类型'一样使用

How i can use that RichTextBoxPrintCtrl without drag and drop it inside the design form? 我如何在不将其拖放到设计表单中的情况下使用RichTextBoxPrintCtrl

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; 一切正常:)谢谢;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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