简体   繁体   English

在WinForm C#中使用ZedGraph动态生成选项卡页数

[英]Make dynamically number of tab pages with ZedGraph in WinForm C#

I have data for several days. 我有几天的数据。 I want to plot that data, one day in one tab page. 我想一天在一个标签页中绘制这些数据。 The tab page can change dynamically corresponding with the number of the day. 标签页可以根据天数动态更改。

Previously, I always make a static page in the design mode. 以前,我总是在设计模式下制作静态页面。 I use ZedGraph control to plot the data. 我使用ZedGraph控件来绘制数据。 I decided how many pages that I need. 我决定需要多少页。 Then it means the number of pages is static. 这意味着页面数是静态的。

Now, I need more dynamically. 现在,我需要更加动态。 I want the number of tab pages can change dynamically. 我希望标签页的数量可以动态更改。 Each page has similar controls inside it. 每个页面内部都有类似的控件。 How to do that? 怎么做? I have no clue about it. 我对此一无所知。

First you create a new class of type UserControl . 首先,创建一个类型为UserControl的新类。 These are meant to act as containers for controls. 这些旨在充当控件的容器。 Then you put everything on it you need in your typical tabpage including the ZedGraph control.. 然后,将您需要的所有内容放到典型的选项卡页面中,包括ZedGraph控件。

Also write your logic there. 也在那里写你的逻辑。

Now, when you need another page you create one and add a new instance of the UC class you have created. 现在,当您需要另一个页面时,可以创建一个页面,并添加一个已创建的UC类的新实例。

You should think a little about dependencies with the rest of you application, including the deleting of the pages; 您应该考虑一下与应用程序其余部分的依赖关系,包括删除页面。 a page controller class comes to mind that can handle these things, if necessary. 我想到一个页面控制器类,可以在必要时处理这些事情。

You could also subclass a tabpage but going the UC way gives go an additional layer of independency; 您也可以继承标签页的子类,但采用UC方式可以增加一层独立性。 you could place the same UC on a form or inside a container control.. 您可以将相同的UC放在窗体上或容器控件内。

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

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