当涉及到programaticaly创建选项卡控件时要知道什么 [英] What to know when it comes to programaticaly create tab control

查看:68
本文介绍了当涉及到programaticaly创建选项卡控件时要知道什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个简单的标签控件,让我可以根据公司过滤数据,但我在这种特殊情况下遇到了问题。我如何在tabcontrol上的文本末尾设置一个按钮来关闭,并有一个带有+符号的标签,根据mysql上的表添加更多公司?



例如:



我有4个标签,这个描述的公司:



测试1

测试2

测试3

测试4

(+)(此选项卡允许我打开一个winform,它将有一个文本框,我插入公司名称,存储在一个名为company的表中。



考虑到这一点,我想要基于数据库创建选项卡的东西。当我单击添加按钮时,它会显示winform窗口以插入公司名称,然后根据公司ID显示,根据company_id升序,它将执行以下操作:





测试1 - 0(此选项卡将是第1个)

测试2 - 2(此选项卡将是第2个)

依旧...



任何ideias如何d这个??





(顺便说一句,我还是个新手,所以不要评价我......) />


我尝试了什么:



试图复制这个而不用programaticaly创建标签。

I'm creating a simple tab control that lets me filter data based on companies, but i'm having problems in this particulary situation. How could i setup a button at the end of the text on the tabcontrol to close, and have a tab with a "+" sign to add more companies based on a table on mysql?

For example:

I've got 4 tabs, with this described companies:

Test 1
Test 2
Test 3
Test 4
(+)(This tab allows me to open a winform which will have a textbox where i insert the name of the company, which is stored in a table called company.

With that in mind, I wanted something to create tabs, based on a database. When i click the add button it shows me that winform window to insert the company name and then it shows based on the company id, ascending according to company_id, with it will do something like this:


Test 1 - 0 (This tab will be the 1st)
Test 2 - 2 (This tab will be the 2nd)
And so on...

Any ideias how to do this??


(Btw, i'm a newbie yet, so don't judge me...)

What I have tried:

tryied to replicate this without programaticaly create tabs.

推荐答案

这是你需要的。



1.主要表格 TabControl 在其中。此控件将有一个空白 TabPage ,标题文本为+。

2.在表单加载时,插入 TabPage 基于数据库内容。在这里,应该使用 Insert 方法而不是添加以确保+ tab最右边。

3.处理控件的 TabIndexChanged 事件。在这里,如果索引是 TabPages.Count - 1 ,请使用 ShowDialog 方法显示表单。

4.在弹出窗体中,将OK / Save / Yes按钮的 DialogResult 属性设置为OK。这将以主窗体形式用于了解是否单击了确定或取消。还要创建一个公共字符串属性,以便主窗体可以获取文本。

5.在主窗体中,检查 PopUpForm.ShowDialog == DialogResult.OK

6.a.如果为true,则在最后一个之前插入新标签页。标签页名称可以从字符串属性中获取。

6.b.什么都不做。

7.可以在任何合适的地方保存新数据(在弹出窗口点击OK或从主窗体上的保存按钮点击时)。

8.处理弹出表单对象。
Here is what you need.

1. Main form with a TabControl in it. This control will have one blank TabPage with header text as "+".
2. On form load, Insert TabPage based on database content. Here, Insert method should be used rather than Add to ensure that + tab is right most.
3. Handle the TabIndexChanged event for the control. Here, if the index is TabPages.Count - 1, show the form using ShowDialog method.
4. In the pop form, set DialogResult property of OK/Save/Yes button to OK. This will be used in main form to know if OK or cancel was clicked. Also create a public string property so that main form can get the text.
5. In main form, check if PopUpForm.ShowDialog == DialogResult.OK.
6.a. If true, Insert a new tab page before the last one. Tab page name can be obtained from string property.
6.b. Do nothing.
7. Saving on new data can be done wherever you find suitable (either when OK is clicked on popup or from a save button on main form).
8. Dispose the pop up form object.


这篇关于当涉及到programaticaly创建选项卡控件时要知道什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆