简体   繁体   English

如何将选项卡控件添加到RichTextBox?

[英]How can I add a tab control to a RichTextBox?

Project description: 项目描述:

Hi, on my project I have 64 client´s they communicate with my main station on a one wire asynchronous bus, now I want to monitor the communication between them. 嗨,在我的项目中,我有64个客户端,它们通过单线asynchronous总线与我的主站进行通信,现在我想监视它们之间的通信。 For that I have a RichTextBox , In that box I see the whole data traffic. 为此,我有一个RichTextBox ,在该框中,我看到了整个数据流量。 Now I want to implement the possibility that when I select a client for example nr. 现在,我想实现一种可能性,当我选择一个客户端时,例如nr。 4 that opens a new RichTextBox on a tab control of my main RichTextBox . 4,打开一个新RichTextBox上我的主要的一个选项卡控件RichTextBox

My problem is that I work with C# since 4 weeks and I don't know how can I do that, I searched in the internet but I didn´t find any example. 我的问题是我从4周开始使用C# ,但我不知道该怎么做,我在互联网上进行了搜索,但没有找到任何示例。 So I ask here for help. 所以我在这里寻求帮助。

Question: How can I make the described requirement?, Is the requirement possible? 问题:如何提出所述要求?该要求是否可能?

Picture for example: 例如图片:

在此处输入图片说明

Sorry for the bad picture, I have only Paint. 对不起,这张照片不好,我只有油漆。 That is my MainWindow at the red arrow´s I want my tabs. 那是我的MainWindow ,位于红色箭头处,我想要我的标签。

I use Microsoft Visual Studio 2015 and WindowsFormsApplication 我使用Microsoft Visual Studio 2015和WindowsFormsApplication

You need to do it the other way arround, add richtextbox to tabpages. 您需要使用另一种方法,将Richtextbox添加到选项卡页。

It can be more simple if you make a custom control that inherits from tabpage. 如果您制作一个自tabpage继承的自定义控件,则可能会更加简单。 The problem with it is that you will be unable to design it via the visual editor. 它的问题是您将无法通过可视化编辑器进行设计。 But since you need just one control in it you can add it via code. 但是由于您只需要其中一个控件,因此可以通过代码添加它。

The class for the custom tab is as follows: 自定义标签的类如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    class CustomTab:TabPage
    {
        public RichTextBox textbox;
        public CustomTab()
        {
            textbox = new RichTextBox();
            this.Controls.Add(textbox);
            textbox.Dock = DockStyle.Fill;
        }
    }
}

As you can see it just inherits from tabpage and on the constructor it adds a RichTextBox that is docked in fill so it will cover all the page. 如您所见,它只是从tabpage继承而来,在构造函数上,它添加了一个RichTextBox,它停靠在fill中,因此它将覆盖所有页面。

The textbox is public, so you can acces it simply with tab.textbox . 该文本框是公共的,因此您只需使用tab.textbox即可对其进行tab.textbox

To add the tabs to the tabcontrol you just need to add the tabcontrol to the form and when you want to add the page simply: 要将选项卡添加到tabcontrol,只需要将tabcontrol添加到表单中,并且仅在要添加页面时:

tabControl1.TabPages.Add(new CustomTab());

Having a custom tab allows you to have all the data and methods that you want (Wich client it is for example) 拥有自定义标签可让您拥有所需的所有数据和方法(例如,这是客户端)

If you have any quaestion feel free to ask 如果您有任何疑问,请随时询问

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

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