コード例 #1
0
ファイル: MainForm.cs プロジェクト: gene-l-thomas/Eto
		void CreateMenuToolBar()
		{
			var about = new Commands.About();
			var quit = new Commands.Quit();

			if (Platform.Supports<MenuBar>())
			{
				Menu = new MenuBar
				{
					Items =
					{
						// custom top-level menu items
						new ButtonMenuItem { Text = "&File", Items = { new Command { MenuText = "File Command" } } },
						new ButtonMenuItem { Text = "&Edit", Items = { new Command { MenuText = "Edit Command" } } },
						new ButtonMenuItem { Text = "&View", Items = { new Command { MenuText = "View Command" } } },
						new ButtonMenuItem { Text = "&Window", Order = 1000, Items = { new Command { MenuText = "Window Command" } } },
					},
					ApplicationItems =
					{
						// custom menu items for the application menu (Application on OS X, File on others)
						new Command { MenuText = "Application command" },
						new ButtonMenuItem { Text = "Application menu item" }
					},
					HelpItems =
					{
						new Command { MenuText = "Help Command" }
					},
					QuitItem = quit,
					AboutItem = about
				};
			}

			if (Platform.Supports<ToolBar>())
			{
				// create and set the toolbar
				ToolBar = new ToolBar();

				ToolBar.Items.Add(about);
				if (Platform.Supports<CheckToolItem>())
				{
					ToolBar.Items.Add(new SeparatorToolItem { Type = SeparatorToolItemType.Divider });
					ToolBar.Items.Add(new CheckToolItem { Text = "Check", Image = TestIcons.TestImage });
				}
				if (Platform.Supports<RadioToolItem>())
				{
					ToolBar.Items.Add(new SeparatorToolItem { Type = SeparatorToolItemType.FlexibleSpace });
					ToolBar.Items.Add(new RadioToolItem { Text = "Radio1", Image = TestIcons.TestIcon, Checked = true });
					ToolBar.Items.Add(new RadioToolItem { Text = "Radio2", Image = TestIcons.TestImage });
				};
			}

		}
コード例 #2
0
ファイル: MainForm.cs プロジェクト: daddycoding/Eto
        void CreateMenuToolBar()
        {
            var about = new Commands.About();
            var quit  = new Commands.Quit();

            if (Platform.Supports <MenuBar>())
            {
                Menu = new MenuBar
                {
                    Items =
                    {
                        // custom top-level menu items
                        new ButtonMenuItem {
                            Text = "&File", Items ={ new Command          {
                                                 MenuText = "File Command"
                                             } }
                        },
                        new ButtonMenuItem {
                            Text = "&Edit", Items ={ new Command          {
                                                 MenuText = "Edit Command"
                                             } }
                        },
                        new ButtonMenuItem {
                            Text = "&View", Items ={ new Command          {
                                                 MenuText = "View Command"
                                             } }
                        },
                        new ButtonMenuItem {
                            Text = "&Window", Order = 1000, Items ={ new Command          {
                                                 MenuText = "Window Command"
                                             } }
                        },
                    },
                    ApplicationItems =
                    {
                        // custom menu items for the application menu (Application on OS X, File on others)
                        new Command        {
                            MenuText = "Application command"
                        },
                        new ButtonMenuItem {
                            Text = "Application menu item"
                        }
                    },
                    HelpItems =
                    {
                        new Command {
                            MenuText = "Help Command"
                        }
                    },
                    QuitItem  = quit,
                    AboutItem = about
                };
            }

            if (Platform.Supports <ToolBar>())
            {
                // create and set the toolbar
                ToolBar = new ToolBar();

                ToolBar.Items.Add(about);
                if (Platform.Supports <CheckToolItem>())
                {
                    ToolBar.Items.Add(new SeparatorToolItem {
                        Type = SeparatorToolItemType.Divider
                    });
                    ToolBar.Items.Add(new CheckToolItem {
                        Text = "Check", Image = TestIcons.TestImage
                    });
                }
                if (Platform.Supports <RadioToolItem>())
                {
                    ToolBar.Items.Add(new SeparatorToolItem {
                        Type = SeparatorToolItemType.FlexibleSpace
                    });
                    ToolBar.Items.Add(new RadioToolItem {
                        Text = "Radio1", Image = TestIcons.TestIcon, Checked = true
                    });
                    ToolBar.Items.Add(new RadioToolItem {
                        Text = "Radio2", Image = TestIcons.TestImage
                    });
                }
                ;
            }
        }
コード例 #3
0
ファイル: MainForm.cs プロジェクト: mhusen/Eto
		void CreateMenuToolBar()
		{
			var about = new Commands.About();
			var quit = new Commands.Quit();

			if (Platform.Supports<MenuBar>())
			{
				var fileCommand = new Command { MenuText = "File Command", Shortcut = Application.Instance.CommonModifier | Keys.F };
				fileCommand.Executed += (sender, e) => Log.Write(sender, "Executed");
				var editCommand = new Command { MenuText = "Edit Command", Shortcut = Keys.Shift | Keys.E };
				editCommand.Executed += (sender, e) => Log.Write(sender, "Executed");
				var viewCommand = new Command { MenuText = "View Command", Shortcut = Keys.Control | Keys.V };
				viewCommand.Executed += (sender, e) => Log.Write(sender, "Executed");
				var windowCommand = new Command { MenuText = "Window Command" };
				windowCommand.Executed += (sender, e) => Log.Write(sender, "Executed");

				var file = new ButtonMenuItem { Text = "&File", Items = { fileCommand } };
				var edit = new ButtonMenuItem { Text = "&Edit", Items = { editCommand } };
                var view = new ButtonMenuItem { Text = "&View", Items = { viewCommand } };
				var window = new ButtonMenuItem { Text = "&Window", Order = 1000, Items = { windowCommand } };

				if (Platform.Supports<CheckMenuItem>())
				{
					edit.Items.AddSeparator();

					var checkMenuItem1 = new CheckMenuItem { Text = "Check Menu Item", Shortcut = Keys.Shift | Keys.K };
					checkMenuItem1.Click += (sender, e) => Log.Write(checkMenuItem1, "Click, {0}, Checked: {1}", checkMenuItem1.Text, checkMenuItem1.Checked);
					checkMenuItem1.CheckedChanged += (sender, e) => Log.Write(checkMenuItem1, "CheckedChanged, {0}: {1}", checkMenuItem1.Text, checkMenuItem1.Checked);
					edit.Items.Add(checkMenuItem1);

					var checkMenuItem2 = new CheckMenuItem { Text = "Initially Checked Menu Item", Checked = true };
					checkMenuItem2.Click += (sender, e) => Log.Write(checkMenuItem2, "Click, {0}, Checked: {1}", checkMenuItem2.Text, checkMenuItem2.Checked);
					checkMenuItem2.CheckedChanged += (sender, e) => Log.Write(checkMenuItem2, "CheckedChanged, {0}: {1}", checkMenuItem2.Text, checkMenuItem2.Checked);
					edit.Items.Add(checkMenuItem2);
				}

				if (Platform.Supports<RadioMenuItem>())
				{
					edit.Items.AddSeparator();

					RadioMenuItem controller = null;
					for (int i = 0; i < 5; i++)
					{
						var radio = new RadioMenuItem(controller) { Text = "Radio Menu Item " + (i + 1) };
						radio.Click += (sender, e) => Log.Write(radio, "Click, {0}, Checked: {1}", radio.Text, radio.Checked);
						radio.CheckedChanged += (sender, e) => Log.Write(radio, "CheckedChanged, {0}: {1}", radio.Text, radio.Checked);
						edit.Items.Add(radio);

						if (controller == null)
						{
							radio.Checked = true; // check the first item initially
							controller = radio;
						}
					}

				}

				Menu = new MenuBar
				{
					Items =
					{
						// custom top-level menu items
						file, edit, view, window
					},
					ApplicationItems =
					{
						// custom menu items for the application menu (Application on OS X, File on others)
						new Command { MenuText = "Application command" },
						new ButtonMenuItem { Text = "Application menu item" }
					},
					HelpItems =
					{
						new Command { MenuText = "Help Command" }
					},
					QuitItem = quit,
					AboutItem = about
				};
			}

			if (Platform.Supports<ToolBar>())
			{
				// create and set the toolbar
				ToolBar = new ToolBar();

				ToolBar.Items.Add(about);
				if (Platform.Supports<CheckToolItem>())
				{
					ToolBar.Items.Add(new SeparatorToolItem { Type = SeparatorToolItemType.Divider });
					ToolBar.Items.Add(new CheckToolItem { Text = "Check", Image = TestIcons.TestImage });
				}
				if (Platform.Supports<RadioToolItem>())
				{
					ToolBar.Items.Add(new SeparatorToolItem { Type = SeparatorToolItemType.FlexibleSpace });
					ToolBar.Items.Add(new RadioToolItem { Text = "Radio1", Image = TestIcons.TestIcon, Checked = true });
					ToolBar.Items.Add(new RadioToolItem { Text = "Radio2", Image = TestIcons.TestImage });
				};
			}

		}
コード例 #4
0
        void CreateMenuToolBar()
        {
            var about = new Commands.About();
            var quit  = new Commands.Quit();

            if (Platform.Supports <MenuBar>())
            {
                var fileCommand = new Command {
                    MenuText = "File Command", Shortcut = Application.Instance.CommonModifier | Keys.F
                };
                fileCommand.Executed += (sender, e) => Log.Write(sender, "Executed");
                var editCommand = new Command {
                    MenuText = "Edit Command", Shortcut = Keys.Shift | Keys.E
                };
                editCommand.Executed += (sender, e) => Log.Write(sender, "Executed");
                var viewCommand = new Command {
                    MenuText = "View Command", Shortcut = Keys.Control | Keys.V
                };
                viewCommand.Executed += (sender, e) => Log.Write(sender, "Executed");
                var windowCommand = new Command {
                    MenuText = "Window Command"
                };
                windowCommand.Executed += (sender, e) => Log.Write(sender, "Executed");

                var file = new ButtonMenuItem {
                    Text = "&File", Items = { fileCommand }
                };
                var edit = new ButtonMenuItem {
                    Text = "&Edit", Items = { editCommand }
                };
                var view = new ButtonMenuItem {
                    Text = "&View", Items = { viewCommand }
                };
                var window = new ButtonMenuItem {
                    Text = "&Window", Order = 1000, Items = { windowCommand }
                };

                if (Platform.Supports <CheckMenuItem>())
                {
                    edit.Items.AddSeparator();

                    var checkMenuItem1 = new CheckMenuItem {
                        Text = "Check Menu Item", Shortcut = Keys.Shift | Keys.K
                    };
                    checkMenuItem1.Click          += (sender, e) => Log.Write(checkMenuItem1, "Click, {0}, Checked: {1}", checkMenuItem1.Text, checkMenuItem1.Checked);
                    checkMenuItem1.CheckedChanged += (sender, e) => Log.Write(checkMenuItem1, "CheckedChanged, {0}: {1}", checkMenuItem1.Text, checkMenuItem1.Checked);
                    edit.Items.Add(checkMenuItem1);

                    var checkMenuItem2 = new CheckMenuItem {
                        Text = "Initially Checked Menu Item", Checked = true
                    };
                    checkMenuItem2.Click          += (sender, e) => Log.Write(checkMenuItem2, "Click, {0}, Checked: {1}", checkMenuItem2.Text, checkMenuItem2.Checked);
                    checkMenuItem2.CheckedChanged += (sender, e) => Log.Write(checkMenuItem2, "CheckedChanged, {0}: {1}", checkMenuItem2.Text, checkMenuItem2.Checked);
                    edit.Items.Add(checkMenuItem2);
                }

                if (Platform.Supports <RadioMenuItem>())
                {
                    edit.Items.AddSeparator();

                    RadioMenuItem controller = null;
                    for (int i = 0; i < 5; i++)
                    {
                        var radio = new RadioMenuItem(controller)
                        {
                            Text = "Radio Menu Item " + (i + 1)
                        };
                        radio.Click          += (sender, e) => Log.Write(radio, "Click, {0}, Checked: {1}", radio.Text, radio.Checked);
                        radio.CheckedChanged += (sender, e) => Log.Write(radio, "CheckedChanged, {0}: {1}", radio.Text, radio.Checked);
                        edit.Items.Add(radio);

                        if (controller == null)
                        {
                            radio.Checked = true;                             // check the first item initially
                            controller    = radio;
                        }
                    }
                }

                Menu = new MenuBar
                {
                    Items =
                    {
                        // custom top-level menu items
                        file, edit, view, window
                    },
                    ApplicationItems =
                    {
                        // custom menu items for the application menu (Application on OS X, File on others)
                        new Command        {
                            MenuText = "Application command"
                        },
                        new ButtonMenuItem {
                            Text = "Application menu item"
                        }
                    },
                    HelpItems =
                    {
                        new Command {
                            MenuText = "Help Command"
                        }
                    },
                    QuitItem  = quit,
                    AboutItem = about
                };
            }

            if (Platform.Supports <ToolBar>())
            {
                // create and set the toolbar
                ToolBar = new ToolBar();

                ToolBar.Items.Add(about);
                if (Platform.Supports <CheckToolItem>())
                {
                    ToolBar.Items.Add(new SeparatorToolItem {
                        Type = SeparatorToolItemType.Divider
                    });
                    ToolBar.Items.Add(new CheckToolItem {
                        Text = "Check", Image = TestIcons.TestImage
                    });
                }
                if (Platform.Supports <RadioToolItem>())
                {
                    ToolBar.Items.Add(new SeparatorToolItem {
                        Type = SeparatorToolItemType.FlexibleSpace
                    });
                    ToolBar.Items.Add(new RadioToolItem {
                        Text = "Radio1", Image = TestIcons.TestIcon, Checked = true
                    });
                    ToolBar.Items.Add(new RadioToolItem {
                        Text = "Radio2", Image = TestIcons.TestImage
                    });
                }
                ;
            }
        }
コード例 #5
0
ファイル: MainForm.cs プロジェクト: philstopford/Eto
        void CreateMenuToolBar()
        {
            var about = new Commands.About();
            var quit  = new Commands.Quit();

            if (Platform.Supports <MenuBar>())
            {
                var saveSettingsItem = new CheckMenuItem {
                    Text = "Save Selected Section"
                };
                saveSettingsItem.Bind(c => c.Checked, TestApplication.Settings, s => s.SaveInitialSection);

                var fileCommand = new Command {
                    MenuText = "File Command", Shortcut = Application.Instance.CommonModifier | Keys.F
                };
                fileCommand.Executed += (sender, e) => Log.Write(sender, "Executed");
                var editCommand = new Command {
                    MenuText = "Edit Command", Shortcut = Keys.Shift | Keys.E
                };
                editCommand.Executed += (sender, e) => Log.Write(sender, "Executed");
                var viewCommand = new Command {
                    MenuText = "View Command", Shortcut = Keys.Control | Keys.Shift | Keys.V
                };
                viewCommand.Executed += (sender, e) => Log.Write(sender, "Executed");
                var windowCommand = new Command {
                    MenuText = "Window Command"
                };
                windowCommand.Executed += (sender, e) => Log.Write(sender, "Executed");

                var crashCommand = new Command {
                    MenuText = "Test Exception"
                };
                crashCommand.Executed += (sender, e) =>
                {
                    throw new InvalidOperationException("This is the exception message");
                };

                var subMenu = new SubMenuItem {
                    Text = "Sub Menu"
                };
                subMenu.Items.Add(new ButtonMenuItem {
                    Text = "Item 1"
                });
                subMenu.Items.Add(new ButtonMenuItem {
                    Text = "Item 2"
                });
                subMenu.Items.Add(new ButtonMenuItem {
                    Text = "Item 3"
                });

                var file = new SubMenuItem {
                    Text = "&File", Items = { saveSettingsItem, fileCommand, crashCommand }
                };
                var edit = new SubMenuItem {
                    Text = "&Edit", Items = { editCommand, subMenu }
                };
                var view = new SubMenuItem {
                    Text = "&View", Items = { viewCommand }
                };
                var window = new SubMenuItem {
                    Text = "&Window", Order = 1000, Items = { windowCommand }
                };

                if (Platform.Supports <CheckMenuItem>())
                {
                    edit.Items.AddSeparator();

                    var checkMenuItem1 = new CheckMenuItem {
                        Text = "Check Menu Item", Shortcut = Keys.Shift | Keys.K
                    };
                    checkMenuItem1.Click          += (sender, e) => Log.Write(sender, "Click, {0}, Checked: {1}", checkMenuItem1.Text, checkMenuItem1.Checked);
                    checkMenuItem1.CheckedChanged += (sender, e) => Log.Write(sender, "CheckedChanged, {0}: {1}", checkMenuItem1.Text, checkMenuItem1.Checked);
                    edit.Items.Add(checkMenuItem1);

                    var checkMenuItem2 = new CheckMenuItem {
                        Text = "Initially Checked Menu Item", Checked = true
                    };
                    checkMenuItem2.Click          += (sender, e) => Log.Write(sender, "Click, {0}, Checked: {1}", checkMenuItem2.Text, checkMenuItem2.Checked);
                    checkMenuItem2.CheckedChanged += (sender, e) => Log.Write(sender, "CheckedChanged, {0}: {1}", checkMenuItem2.Text, checkMenuItem2.Checked);
                    edit.Items.Add(checkMenuItem2);

                    var checkMenuItem3 = new CheckCommand {
                        MenuText = "Check Command", Shortcut = Keys.Shift | Keys.K
                    };
                    checkMenuItem3.Executed       += (sender, e) => Log.Write(sender, "Executed, {0}, Checked: {1}", checkMenuItem3.MenuText, checkMenuItem3.Checked);
                    checkMenuItem3.CheckedChanged += (sender, e) => Log.Write(sender, "CheckedChanged, {0}: {1}", checkMenuItem3.MenuText, checkMenuItem3.Checked);
                    edit.Items.Add(checkMenuItem3);

                    checkMenuItem1.Click += (sender, e) => checkMenuItem3.Checked = !checkMenuItem3.Checked;
                }

                if (Platform.Supports <RadioMenuItem>())
                {
                    edit.Items.AddSeparator();

                    RadioMenuItem controller = null;
                    for (int i = 0; i < 5; i++)
                    {
                        var radio = new RadioMenuItem(controller)
                        {
                            Text = "Radio Menu Item " + (i + 1)
                        };
                        if (controller == null)
                        {
                            radio.Checked = true;                             // check the first item initially
                            controller    = radio;
                        }
                        radio.Click          += (sender, e) => Log.Write(radio, "Click, {0}, Checked: {1}", radio.Text, radio.Checked);
                        radio.CheckedChanged += (sender, e) => Log.Write(radio, "CheckedChanged, {0}: {1}", radio.Text, radio.Checked);
                        edit.Items.Add(radio);
                    }

                    edit.Items.AddSeparator();

                    RadioCommand commandController = null;
                    for (int i = 0; i < 2; i++)
                    {
                        var radio = new RadioCommand {
                            MenuText = "Radio Command " + (i + 1), Controller = commandController
                        };
                        if (commandController == null)
                        {
                            radio.Checked     = true;                         // check the first item initially
                            commandController = radio;
                        }
                        radio.Executed       += (sender, e) => Log.Write(radio, "Executed, {0}, Checked: {1}", radio.MenuText, radio.Checked);
                        radio.CheckedChanged += (sender, e) => Log.Write(radio, "CheckedChanged, {0}: {1}", radio.MenuText, radio.Checked);
                        edit.Items.Add(radio);
                    }
                }

                edit.Items.AddSeparator();
                var hiddenItem = new ButtonMenuItem {
                    Text = "This button should not be visible!", Visible = false
                };
                var toggleHiddenItem = new ButtonMenuItem {
                    Text = "Toggle Hidden Item"
                };
                toggleHiddenItem.Click += (sender, e) => hiddenItem.Visible = !hiddenItem.Visible;
                edit.Items.Add(hiddenItem);
                edit.Items.Add(toggleHiddenItem);


                Menu = new MenuBar
                {
                    Items =
                    {
                        // custom top-level menu items
                        file, edit, view, window
                    },
                    ApplicationItems =
                    {
                        // custom menu items for the application menu (Application on OS X, File on others)
                        new Command        {
                            MenuText = "Application command"
                        },
                        new ButtonMenuItem {
                            Text = "Application menu item"
                        }
                    },
                    HelpItems =
                    {
                        new Command {
                            MenuText = "Help Command"
                        }
                    },
                    QuitItem  = quit,
                    AboutItem = about
                };
            }

            if (Platform.Supports <ToolBar>())
            {
                // create and set the toolbar
                ToolBar = new ToolBar();

                ToolBar.Items.Add(about);
                if (Platform.Supports <CheckToolItem>())
                {
                    ToolBar.Items.Add(new SeparatorToolItem {
                        Type = SeparatorToolItemType.Divider
                    });
                    ToolBar.Items.Add(LogEvents(new CheckToolItem {
                        Text = "Check", Image = TestIcons.TestImage
                    }));
                }
                ToolBar.Items.Add(new SeparatorToolItem {
                    Type = SeparatorToolItemType.Space
                });
                ButtonToolItem clickButton = LogEvents(new ButtonToolItem {
                    Text = "Click Me", Image = TestIcons.Logo
                });
                ToolBar.Items.Add(clickButton);
                if (Platform.Supports <RadioToolItem>())
                {
                    ToolBar.Items.Add(new SeparatorToolItem {
                        Type = SeparatorToolItemType.FlexibleSpace
                    });
                    ToolBar.Items.Add(LogEvents(new RadioToolItem {
                        Text = "Radio1", Image = TestIcons.Logo, Checked = true
                    }));
                    ToolBar.Items.Add(LogEvents(new RadioToolItem {
                        Text = "Radio2", Image = TestIcons.TestImage
                    }));
                    ToolBar.Items.Add(LogEvents(new RadioToolItem {
                        Text = "Radio3 (Disabled)", Image = TestIcons.TestImage, Enabled = false
                    }));
                }

                // add an invisible button and separator and allow them to be toggled.
                var invisibleButton = LogEvents(new ButtonToolItem {
                    Text = "Invisible", Visible = false
                });
                var sep = new SeparatorToolItem {
                    Type = SeparatorToolItemType.Divider, Visible = false
                };
                ToolBar.Items.Add(sep);
                ToolBar.Items.Add(invisibleButton);
                clickButton.Click += (sender, e) =>
                {
                    invisibleButton.Visible = !invisibleButton.Visible;
                    sep.Visible             = invisibleButton.Visible;
                };
            }
        }