GetForm() public method

public GetForm ( ) : Form
return Form
示例#1
0
        public void MainMenu_GetForm_AddedToForm_ReturnsExpected()
        {
            var form = new Form
            {
                Menu = new MainMenu()
            };

            MainMenu menu = form.Menu;

            Assert.Equal(form, menu.GetForm());
            Assert.Equal(form, menu.GetFormUnsafe());
        }
示例#2
0
		public void GetFormTest ()
		{
			Form myform = new Form ();
			myform.ShowInTaskbar = false;
			myform.Name = "New Form";
			MainMenu mymainmenu1 = new MainMenu ();
			MenuItem menuitem1 = new MenuItem ();
			menuitem1.Text = "item1";
			mymainmenu1.MenuItems.Add (menuitem1);
			myform.Menu = mymainmenu1;
			Assert.AreEqual ("New Form", mymainmenu1.GetForm().Name, "#10");
			myform.Dispose ();
		}
示例#3
0
        public void MainMenu_Dispose_HasForm_Success()
        {
            var form = new Form
            {
                Menu = new MainMenu()
            };

            MainMenu menu = form.Menu;

            menu.Dispose();
            Assert.Null(menu.GetForm());
            Assert.Null(form.Menu);
        }
示例#4
0
        public void MainMenu_Ctor_Default()
        {
            var menu = new MainMenu();

            Assert.Empty(menu.MenuItems);
            Assert.False(menu.IsParent);
            Assert.Equal(RightToLeft.Inherit, menu.RightToLeft);
            Assert.Null(menu.GetForm());
            Assert.Empty(menu.Name);
            Assert.Null(menu.Site);
            Assert.Null(menu.Container);
            Assert.Null(menu.Tag);
        }
示例#5
0
        public void MainMenu_Dispose_HasOwnerForm_Success()
        {
            var parentForm = new Form {
                IsMdiContainer = true
            };
            var form = new Form
            {
                Menu      = new MainMenu(),
                MdiParent = parentForm
            };

            MainMenu menu = form.MergedMenu;

            menu.Dispose();
            Assert.Null(menu.GetForm());
            Assert.Null(form.Menu);
        }
示例#6
0
        public void MainMenu_Ctor_MenuItemArray(MenuItem[] items, bool expectedIsParent)
        {
            var menu = new MainMenu(items);

            Assert.Equal(items ?? new MenuItem[0], menu.MenuItems.Cast <MenuItem>());
            for (int i = 0; i < (items?.Length ?? 0); i++)
            {
                Assert.Equal(i, menu.MenuItems[i].Index);
                Assert.Equal(menu, menu.MenuItems[i].Parent);
            }
            Assert.Equal(expectedIsParent, menu.IsParent);
            Assert.Equal(RightToLeft.Inherit, menu.RightToLeft);
            Assert.Null(menu.GetForm());
            Assert.Empty(menu.Name);
            Assert.Null(menu.Site);
            Assert.Null(menu.Container);
            Assert.Null(menu.Tag);
        }
示例#7
0
        public void MainMenu_CloneMenu_Invoke_Success(MenuItem[] items)
        {
            var source = new MainMenu(items)
            {
                RightToLeft = RightToLeft.No
            };
            MainMenu menu = source.CloneMenu();

            Assert.NotSame(source, menu);
            Assert.Equal(items.Select(m => m.Name), menu.MenuItems.Cast <MenuItem>().Select(m => m.Name));
            Assert.Equal(source.IsParent, menu.IsParent);
            Assert.Equal(RightToLeft.Inherit, menu.RightToLeft);
            Assert.Null(menu.GetForm());
            Assert.Empty(menu.Name);
            Assert.Null(menu.Site);
            Assert.Null(menu.Container);
            Assert.Null(menu.Tag);
        }
示例#8
0
文件: MenuItem.cs 项目: nsivov/mono
        private void PopulateWindowMenu()
        {
            if (mdilist)
            {
                if (mdilist_items == null)
                {
                    mdilist_items = new Hashtable();
                    mdilist_forms = new Hashtable();
                }

                do
                {
                    MainMenu main = GetMainMenu();
                    if (main == null || main.GetForm() == null)
                    {
                        break;
                    }

                    Form form = main.GetForm();
                    mdicontainer = form.MdiContainer;
                    if (mdicontainer == null)
                    {
                        break;
                    }


                    // Remove closed forms
                    MenuItem[] items = new MenuItem[mdilist_items.Count];
                    mdilist_items.Keys.CopyTo(items, 0);
                    foreach (MenuItem item in items)
                    {
                        Form mdichild = (Form)mdilist_items [item];
                        if (!mdicontainer.mdi_child_list.Contains(mdichild))
                        {
                            mdilist_items.Remove(item);
                            mdilist_forms.Remove(mdichild);
                            MenuItems.Remove(item);
                        }
                    }

                    // Add new forms and update state for existing forms.
                    for (int i = 0; i < mdicontainer.mdi_child_list.Count; i++)
                    {
                        Form     mdichild = (Form)mdicontainer.mdi_child_list[i];
                        MenuItem item;
                        if (mdilist_forms.Contains(mdichild))
                        {
                            item = (MenuItem)mdilist_forms [mdichild];
                        }
                        else
                        {
                            item = new MenuItem();
                            item.is_window_menu_item = true;
                            item.Click              += new EventHandler(MdiWindowClickHandler);
                            mdilist_items [item]     = mdichild;
                            mdilist_forms [mdichild] = item;
                            MenuItems.AddNoEvents(item);
                        }
                        item.Visible = mdichild.Visible;
                        item.Text    = "&" + (i + 1).ToString() + " " + mdichild.Text;
                        item.Checked = form.ActiveMdiChild == mdichild;
                    }
                } while (false);
            }
            else
            {
                // Remove all forms
                if (mdilist_items != null)
                {
                    foreach (MenuItem item in mdilist_items.Values)
                    {
                        MenuItems.Remove(item);
                    }

                    mdilist_forms.Clear();
                    mdilist_items.Clear();
                }
            }
        }