MDI Application


1. Giao diện
Kéo component MenuStrip vào form. Click vào ô Collection trong Properties của MenuStrip và thêm vào 4 sub-menus là Forms, Report, Help, Exit như sau:


Submenu Customer Details có event Click với nhiệm vụ hiển thị ra Form Customer Details

đoạn code cho event này 
                      if (this.MdiChildren.Length > 0)
            {
                Form[] activeform = this.MdiChildren;
                bool flag = false;
                for (int i = 0; i < activeform.Length; i++)
                {
                    if (activeform[i].Text == "Customer Details")
                    {
                        MessageBox.Show("The window is already running.", "Sales Management", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        flag = true;
                        break;
                    }
                    if (!flag)
                    {
                        CreateCustomerDetailsForm();
                    }
                }
            }
            else
            {
                CreateCustomerDetailsForm();
            }

Ngoài ra Form còn có ContextMenuStrip tạo shortcut tới các menu khi click chuột phải.
Kéo component ContextMenuStrip vào form rồi tạo các menu muốn đến như đối với MenuStrip

Để activate được ContextMenuStrip ta gán nó vào property ContextMenuStrip của Form. Các submenu tại đây có event Click tương tự như với các submenu ở trên

2. Giao diện

Kéo component MenuStrip vào form. Click vào ô Collection trong Properties của MenuStrip và thêm vào 3 sub-menus là Project, Options, Help như trên.
Submenu Project Details có event Click với nhiệm vụ hiển thị ra Project Details Form như sau:
đoạn code có nội dụng 
            ProjectDetails2 pd = new ProjectDetails2();
            pd.MdiParent = this;
            pd.Show();

tương tự với Staff Details cũng có event Click:
             
 if (this.MdiChildren.Length > 0)
            {
                Form[] activeform = this.MdiChildren;
                bool flag = false;
                for (int i = 0; i < activeform.Length; i++)
                {
                    if (activeform[i].Text == "Customer Details")
                    {
                        MessageBox.Show("The window is already running.", "Sales Management", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        flag = true;
                        break;
                    }
                    if (!flag)
                    {
                        CreateStaffDetailsForm();
                    }
                }
            }
            else
            {
                CreateStaffDetailsForm();
            }

0 nhận xét:

Đăng nhận xét

 
Copyright © Pha Quế Domination