使用VB.Net
我的表单名称为“Employee Entry”
用户想要从5个标签中打开一个员工条目......
例如
When the user open a Employee Entry form, while entering the details at that same time, user again open a employee entry form (2nd Employee entry form show like a new employee entry from with out any details)
更多示例
We can open Google, Yahoo, in one browser (by using Tab Function).
如何做到这一点。
需要vb.net代码帮助
答案 0 :(得分:1)
我假设这是WinForms?您应该将Employee Entry设计为用户控件。然后,您可以在新员工的每次请求时将该控件的新实例添加到表单中。您很可能有一个单独的Employee对象,您可以将其传递给EmployeeEntry用户控件的每个实例。
<强> EDIT1 强>
创建一个顶部带有菜单条的表单和一个名为tsmiNewEmployee的菜单项。将选项卡控件添加到名为tabEntryForms的表单中,并将其填充样式设置为Dock。从中删除所有默认标签页。
添加课程:
public class EmployeeRecord
{
public string FirstName { get; set; }
public string LastName { get; set; }
public DateTime HireDate { get; set; }
}
添加名为EmployeeEntry的USerControl。将osme Firts /姓氏编辑为cotrols,等等。添加“保存”按钮和“取消”按钮。
public partial class EmployeeEntry : UserControl
{
public event EventHandler Save;
public event EventHandler Cancel;
private EmployeeRecord empBeingEdited = null;
public EmployeeRecord Employee
{
get
{
return empBeingEdited;
}
set
{
empBeingEdited = value;
if (empBeingEdited == null)
{
// clear controls
}
else
{
// populate controls with employee values
}
}
}
public EmployeeEntry()
{
InitializeComponent();
}
private void btnSave_Click(object sender, EventArgs e)
{
if (Save != null)
Save(this, EventArgs.Empty);
}
private void btnCancel_Click(object sender, EventArgs e)
{
if (Cancel != null)
Cancel(this, EventArgs.Empty);
}
}
在主窗体中有标签控件:
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private void tsmiNewEmployee_Click(object sender, EventArgs e)
{
TabPage tab = new TabPage("New Employee Entry");
EmployeeEntry empEntry = new EmployeeEntry();
empEntry.Employee = new EmployeeRecord();
empEntry.Save += new EventHandler(EmployeeEntry_Save);
empEntry.Cancel += new EventHandler(EmployeeEntry_Cancel);
tab.Controls.Add(empEntry);
empEntry.Dock = DockStyle.Fill;
tabEntryForms.TabPages.Add(tab);
}
private void EmployeeEntry_Save(object source, EventArgs args)
{
EmployeeEntry empEntry = source as EmployeeEntry;
MessageBox.Show("Saved");
TabPage parentTab = empEntry.Parent as TabPage;
parentTab.Controls.Remove(empEntry);
tabEntryForms.Controls.Remove(parentTab);
}
private void EmployeeEntry_Cancel(object source, EventArgs args)
{
EmployeeEntry empEntry = source as EmployeeEntry;
MessageBox.Show("NOT Saved");
TabPage parentTab = empEntry.Parent as TabPage;
parentTab.Controls.Remove(empEntry);
tabEntryForms.Controls.Remove(parentTab);
}
}
这应该让你开始。