开发者

How to repeat a the windows form (Tab Function)

Using VB.Net

I am having the form name as "Employee Entry"

User want to open a Employee Entry from in 5 tabs...

For Example

When the user open a Employee Entry form, while entering the details at that same time, user again open a employee ent开发者_StackOverflow中文版ry form (2nd Employee entry form show like a new employee entry from with out any details)

More Example

We can open Google, Yahoo, in one browser (by using Tab Function).

How to make this.

Need vb.net code Help


I'm assuming this is WinForms? You should design your Employee Entry as a User Control. You can then add a new instance of that control to your Form on each request of a new Employee. You would most likely have a seperate Employee object that you could pass to each instance of your EmployeeEntry user control.

EDIT1

Create a form with a menu strip across the top and a menu item called tsmiNewEmployee. Add a tab control to the form named tabEntryForms and set its fill style to Dock. Delete all default tab pages from it.

Add Class:

public class EmployeeRecord
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public DateTime HireDate { get; set; }
}

Add USerControl named EmployeeEntry. Puts osme Firts/Last name edit cotrols on it, etc. Add a Save button and a Cancel Button.

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);
    }
}

And in your main form that has the tab control:

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);


    }
}

That should get you started.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜