//Everything has to be sent in on the constructor since things do not auto-refresh / update this is a limitation public LinuxTrayIcon(string TooTip, string IconPath, Avalonia.Controls.ContextMenu _menu) { Dispatcher.UIThread.Post(() => { var ctxMnu = new Eto.Forms.ContextMenu(); foreach (var x in _menu.Items.Cast <Avalonia.Controls.MenuItem>()) { ButtonMenuItem bmi = new ButtonMenuItem(); bmi.Text = x.Header.ToString(); bmi.Command = new Command((s, e) => { Dispatcher.UIThread.Post(() => { x.Command.Execute(null); }); }); ctxMnu.Items.Add(bmi); } ClientSize = new Size(200, 200); _tray = new TrayIndicator { Image = Eto.Drawing.Icon.FromResource(IconPath.Replace("resm:", "")), Menu = ctxMnu, Title = ToolTip }; _tray.Show(); _tray.Visible = true; }); }
void LogEvents(ContextMenu menu) { foreach (var item in menu.Items.OfType<ButtonMenuItem>()) { LogEvents(item); } }
void LogEvents(ContextMenu menu) { foreach (var item in menu.MenuItems.OfType<ImageMenuItem>()) { LogEvents(item); } }
ContextMenu CreateMenu() { var menu = new ContextMenu(); menu.MenuItems.Add (new ImageMenuItem{ Text = "Item 1" }); menu.MenuItems.Add (new ImageMenuItem{ Text = "Item 2" }); menu.MenuItems.Add (new ImageMenuItem{ Text = "Item 3" }); menu.MenuItems.Add (new ImageMenuItem{ Text = "Item 4" }); LogEvents (menu); return menu; }
void Init() { //_contextMenuRightMenu _contextMenuRightMenu = new ContextMenu(); var addItem = new ButtonMenuItem {Text = "Add"}; addItem.Click += addItem_Click; var delItem = new ButtonMenuItem {Text = "Delete"}; delItem.Click += delItem_Click; _contextMenuRightMenu.Items.Add(addItem); _contextMenuRightMenu.Items.Add(delItem); //_gridViewHeader _gridViewHeader = new GridView { AllowMultipleSelection = false, BackgroundColor = Colors.White, Size = new Size(200, 200), ShowCellBorders = true }; //_gridViewHeader.CellEditing += _gridViewHeader_CellEditing; //_gridViewHeader.CellEdited += _gridViewHeader_CellEdited; _gridViewHeader.Columns.Add(new GridColumn { HeaderText = "Key", DataCell = new TextBoxCell("Key"), Editable = true, Sortable = true, AutoSize = true }); _gridViewHeader.Columns.Add(new GridColumn { HeaderText = "Value", DataCell = new TextBoxCell("Value"), Editable = true, Sortable = true, AutoSize = false, Width = 200 }); _gridViewHeader.ContextMenu = _contextMenuRightMenu; _gridViewHeader.MouseUp += (sender, e) => { if (e.Buttons == MouseButtons.Alternate) { if (_gridViewHeader.ContextMenu != null) _gridViewHeader.ContextMenu.Show(this); } }; var layout = new DynamicLayout { Padding = new Padding(20, 20), Spacing = new Size(10, 10) }; layout.AddRow(_gridViewHeader); layout.Add(null); this.Content = layout; }
ContextMenu CreateMenu() { var menu = new ContextMenu(); menu.Items.Add(new ButtonMenuItem { Text = "Item 1" }); menu.Items.Add(new ButtonMenuItem { Text = "Item 2" }); menu.Items.Add(new ButtonMenuItem { Text = "Item 3" }); menu.Items.Add(new ButtonMenuItem { Text = "Item 4" }); var subMenu = menu.Items.GetSubmenu("Sub Menu"); subMenu.Items.Add(new ButtonMenuItem { Text = "Item 5" }); subMenu.Items.Add(new ButtonMenuItem { Text = "Item 6" }); LogEvents(menu); return menu; }
void InitUi() { //_itemRefreshStatus _itemRefreshStatus = new ButtonMenuItem { Text = StrRes.GetString("StrRefreshStatus", "Refresh Status") }; _itemRefreshStatus.Click += _itemRefreshStatus_Click; //_itemCopyServerCode _itemCopyServerCode = new ButtonMenuItem { Text = StrRes.GetString("StrCopyServerCode", "Copy ServerCode") }; _itemCopyServerCode.Click += _itemCopyServerCode_Click; //_itemAdd _itemAdd = new ButtonMenuItem { Text = StrRes.GetString("StrAdd","Add") }; _itemAdd.Click += _itemAdd_Click; //_itemEdit _itemEdit = new ButtonMenuItem { Text = StrRes.GetString("StrEdit","Edit") }; _itemEdit.Click += _itemEdit_Click; //_itemDelete _itemDelete = new ButtonMenuItem { Text = StrRes.GetString("StrDelete","Delete") }; _itemDelete.Click += _itemDelete_Click; //rightMenu_Webshell _rightMenuWebshell = new ContextMenu(); _rightMenuWebshell.Items.Add(_itemRefreshStatus); _rightMenuWebshell.Items.Add(_itemCopyServerCode); _rightMenuWebshell.Items.Add(new SeparatorMenuItem()); _rightMenuWebshell.Items.Add(_itemAdd); _rightMenuWebshell.Items.Add(_itemEdit); _rightMenuWebshell.Items.Add(_itemDelete); _rightMenuWebshell.Items.Add(new SeparatorMenuItem()); //_gridViewShell _gridViewShell = CreateListView(); _gridViewShell.ContextMenu = _rightMenuWebshell; _gridViewShell.MouseUp += (sender, e) => { if (e.Buttons == MouseButtons.Alternate) { _gridViewShell.ContextMenu.Show(_gridViewShell); } }; //_gridViewShell.CellDoubleClick += _gridViewShell_CellDoubleClick; //_gridViewShell.ColumnHeaderClick += _gridViewShell_ColumnHeaderClick; var layout = new DynamicLayout { Padding = new Padding(0), Spacing = new Size(10, 10) }; layout.Add(_gridViewShell); this.Content = layout; }
Control ImagesAndMenu() { var control = new TreeView { Size = new Size(100, 150) }; var menu = new ContextMenu (); var item = new ImageMenuItem{ Text = "Click Me!"}; item.Click += delegate { if (control.SelectedItem != null) Log.Write (item, "Click, Rows: {0}", control.SelectedItem.Text); else Log.Write (item, "Click, no item selected"); }; menu.MenuItems.Add (item); control.ContextMenu = menu; LogEvents (control); control.DataStore = CreateTreeItem (0, "Item", Image); return control; }
ContextMenu CreateMenu() { if (menu != null) return menu; menu = new ContextMenu(); menu.Opening += (sender, e) => Log.Write(sender, "Opening"); menu.Closed += (sender, e) => Log.Write(sender, "Closed"); menu.Items.Add(new ButtonMenuItem { Text = "Item 1" }); menu.Items.Add(new ButtonMenuItem { Text = "Item 2", Shortcut = Keys.Control | Keys.I }); menu.Items.Add(new ButtonMenuItem { Text = "Item 3", Shortcut = Keys.Shift | Keys.I }); menu.Items.Add(new ButtonMenuItem { Text = "Item 4", Shortcut = Keys.Alt | Keys.I }); var subMenu = menu.Items.GetSubmenu("Sub Menu"); subMenu.Items.Add(new ButtonMenuItem { Text = "Item 5", Shortcut = Keys.Application | Keys.I }); subMenu.Items.Add(new ButtonMenuItem { Text = "Item 6", Shortcut = Keys.I }); menu.Items.AddSeparator(); RadioMenuItem radioController; menu.Items.Add(radioController = new RadioMenuItem { Text = "Radio 1" }); menu.Items.Add(new RadioMenuItem(radioController) { Text = "Radio 2", Checked = true }); menu.Items.Add(new RadioMenuItem(radioController) { Text = "Radio 3", Shortcut = Keys.R }); menu.Items.Add(new RadioMenuItem(radioController) { Text = "Radio 4" }); menu.Items.AddSeparator(); menu.Items.Add(new CheckMenuItem { Text = "Check 1" }); menu.Items.Add(new CheckMenuItem { Text = "Check 2", Shortcut = Keys.Control | Keys.Alt | Keys.G, Checked = true }); menu.Items.Add(new CheckMenuItem { Text = "Check 3", Shortcut = Keys.Control | Keys.Shift | Keys.G }); menu.Items.Add(new CheckMenuItem { Text = "Check 4", Shortcut = Keys.Control | Keys.Application | Keys.G }); menu.Items.Add(new CheckMenuItem { Text = "Check 5", Shortcut = Keys.Shift | Keys.Alt | Keys.G }); menu.Items.Add(new CheckMenuItem { Text = "Check 6", Shortcut = Keys.Shift | Keys.Application | Keys.G }); menu.Items.Add(new CheckMenuItem { Text = "Check 7", Shortcut = Keys.Alt | Keys.Application | Keys.G }); LogEvents(menu); return menu; }
GridView WithContextMenu () { var control = Default (); control.AllowMultipleSelection = true; var menu = new ContextMenu (); var item = new ImageMenuItem{ Text = "Click Me!"}; item.Click += delegate { if (control.SelectedRows.Count () > 0) Log.Write (item, "Click, Rows: {0}", SelectedRowsString (control)); else Log.Write (item, "Click, no item selected"); }; menu.MenuItems.Add (item); control.ContextMenu = menu; return control; }
public PlotHandler() { var pview = new global::OxyPlot.WindowsForms.PlotView(); Control = pview; ContextMenu cmenu = new ContextMenu(); cmenu.Items.Add(new ButtonMenuItem((sender, e) => { var pngExporter = new PngExporter { Width = pview.Width, Height = pview.Height, Background = OxyColors.White }; var bitmap = pngExporter.ExportToBitmap(pview.Model); System.Windows.Forms.Clipboard.SetImage(bitmap); }) { Text = "Copy" }); cmenu.Items.Add(new ButtonMenuItem((sender, e) => { var pngExporter = new PngExporter { Width = pview.Width * 2, Height = pview.Height * 2, Background = OxyColors.White }; var bitmap = pngExporter.ExportToBitmap(pview.Model); System.Windows.Forms.Clipboard.SetImage(bitmap); }) { Text = "Copy @ 2x" }); cmenu.Items.Add(new ButtonMenuItem((sender, e) => { var pngExporter = new PngExporter { Width = pview.Width * 3, Height = pview.Height * 3, Background = OxyColors.White }; var bitmap = pngExporter.ExportToBitmap(pview.Model); System.Windows.Forms.Clipboard.SetImage(bitmap); }) { Text = "Copy @ 3x" }); cmenu.Items.Add(new ButtonMenuItem((sender, e) => { var sfd = new SaveFileDialog(); sfd.Title = "Save Chart to PNG"; sfd.Filters.Add(new FileFilter("PNG File", new string[] { ".png" })); sfd.CurrentFilterIndex = 0; if (sfd.ShowDialog(this.Widget) == DialogResult.Ok) { var pngExporter = new PngExporter { Width = pview.Width, Height = pview.Height, Background = OxyColors.White }; pngExporter.ExportToFile(Model, sfd.FileName); } }) { Text = "Save to File" }); cmenu.Items.Add(new ButtonMenuItem((sender, e) => { var sfd = new SaveFileDialog(); sfd.Title = "Save Chart to PNG"; sfd.Filters.Add(new FileFilter("PNG File", new string[] { ".png" })); sfd.CurrentFilterIndex = 0; if (sfd.ShowDialog(this.Widget) == DialogResult.Ok) { var pngExporter = new PngExporter { Width = pview.Width * 2, Height = pview.Height * 2, Background = OxyColors.White }; pngExporter.ExportToFile(Model, sfd.FileName); } }) { Text = "Save to File @ 2x" }); cmenu.Items.Add(new ButtonMenuItem((sender, e) => { var sfd = new SaveFileDialog(); sfd.Title = "Save Chart to PNG"; sfd.Filters.Add(new FileFilter("PNG File", new string[] { ".png" })); sfd.CurrentFilterIndex = 0; if (sfd.ShowDialog(this.Widget) == DialogResult.Ok) { var pngExporter = new PngExporter { Width = pview.Width * 3, Height = pview.Height * 3, Background = OxyColors.White }; pngExporter.ExportToFile(Model, sfd.FileName); } }) { Text = "Save to File @ 3x" }); cmenu.Items.Add(new ButtonMenuItem((sender, e) => { pview.Model.ResetAllAxes(); pview.Model.InvalidatePlot(false); }) { Text = "Reset to Default View" }); this.ContextMenu = cmenu; }
/// <summary> /// Raises the <see cref="Closed"/> event. /// </summary> public void OnClosed(ContextMenu widget, EventArgs e) { widget.Platform.Invoke(() => widget.OnClosed(e)); }
ContextMenu CreateFileRightMenu(Status status) { //contextMenu var contextMenu = new ContextMenu(); contextMenu.Items.Add(new Actions.ItemRefresh(status)); contextMenu.Items.AddSeparator(); contextMenu.Items.Add(new Actions.ItemUpload(status)); contextMenu.Items.Add(new Actions.ItemDownload(status)); contextMenu.Items.Add(new Actions.ItemDownloadToServer(status)); contextMenu.Items.AddSeparator(); contextMenu.Items.Add(new Actions.ItemDelete(status)); contextMenu.Items.Add(new Actions.ItemEdit(status)); contextMenu.Items.Add(new Actions.ItemCopy(status)); contextMenu.Items.Add(new Actions.ItemPaste(status)); contextMenu.Items.Add(new Actions.ItemRename(status)); contextMenu.Items.Add(new Actions.ItemModifyTime(status)); var create = contextMenu.Items.GetSubmenu(StrRes.GetString("StrNew", "New")); create.Items.Add(new Actions.ItemCreateDir(status)); create.Items.Add(new Actions.ItemCreateFile(status)); return contextMenu; }
void Init() { //_textboxUrl _textboxUrl = new TextBox(); _textboxUrl.KeyDown += _textboxUrl_KeyDown; //_buttonDir _buttonDir = new Button {Text = StrRes.GetString("StrDir","Dir")}; _buttonDir.Click += _buttonDir_Click; //_treeViewDirs _treeViewDirs = new TreeViewPlus(); _treeViewDirs.Activated += _treeViewDirs_Activated; //_itemCopyNodePath _itemCopyNodePath = new ButtonMenuItem { Text = StrRes.GetString("StrCopyNodePath", "Copy Path") }; _itemCopyNodePath.Click += _itemCopyNodePath_Click; //rightMenu_TreeViewDirs var rightMenuTreeViewDirs = new ContextMenu(); rightMenuTreeViewDirs.Items.Add(_itemCopyNodePath); _treeViewDirs.ContextMenu = rightMenuTreeViewDirs; _treeViewDirs.MouseUp += (sender, e) => { if (e.Buttons == MouseButtons.Alternate) { _treeViewDirs.ContextMenu.Show(_treeViewDirs); } }; _gridViewFile = new GridView { AllowMultipleSelection = false, BackgroundColor = Colors.White, ShowCellBorders = false, RowHeight = 21 }; _gridViewFile.CellEditing += _gridViewFile_CellEditing; _gridViewFile.CellEdited += _gridViewFile_CellEdited; _gridViewFile.CellDoubleClick += _gridViewFile_CellDoubleClick; _gridViewFile.ColumnHeaderClick += _gridViewFile_ColumnHeaderClick; _gridViewFile.Columns.Add(new GridColumn { ID = "Image", HeaderText = ">", //DataCell = new ImageTextCell("Image","Name"), DataCell = new ImageViewCell("Image"), Sortable = true, Resizable = false, Width = 21 }); _gridViewFile.Columns.Add(new GridColumn { ID = "Name", HeaderText = StrRes.GetString("StrName","Name"), DataCell = new TextBoxCell("Name"), Sortable = true, AutoSize = false, Editable = true, Width = 200 }); _gridViewFile.Columns.Add(new GridColumn { ID = "Time", HeaderText = StrRes.GetString("StrTime","Time"), DataCell = new TextBoxCell("FileMTime"), Sortable = true, AutoSize = false, Editable = true, Width = 150 }); _gridViewFile.Columns.Add(new GridColumn { ID = "Size", HeaderText = StrRes.GetString("StrSize","Size"), DataCell = new TextBoxCell("FileSize"), Sortable = true, AutoSize = false, Width = 100 }); _gridViewFile.Columns.Add(new GridColumn { ID = "Attribute", HeaderText = StrRes.GetString("StrAttribute","Attribute"), DataCell = new TextBoxCell("FileAttributes"), Sortable = true, AutoSize = false, Width = 70 }); _gridViewFile.MouseUp += (sender, e) => { if (e.Buttons == MouseButtons.Alternate) { if (_gridViewFile.ContextMenu!=null) _gridViewFile.ContextMenu.Show(_gridViewFile); } }; var layout = new DynamicLayout { Padding = new Padding(0, 0), Spacing = new Size(5, 5) }; layout.BeginVertical(); layout.BeginHorizontal(); layout.AddCentered(_textboxUrl, xscale: true, horizontalCenter: false); layout.AddCentered(_buttonDir, horizontalCenter: false); layout.EndHorizontal(); layout.EndVertical(); layout.AddRow(new Splitter { Panel1 = _treeViewDirs, Panel2 = _gridViewFile, Orientation = SplitterOrientation.Horizontal, Position = 200, }); Content = layout; }
/// <summary> /// Raises the <see cref="Opening"/> event. /// </summary> public void OnOpening(ContextMenu widget, EventArgs e) { widget.Platform.Invoke(() => widget.OnOpening(e)); }
public void SetContextMenu(Eto.Forms.ContextMenu contextMenu) { _contextMenu = contextMenu; }
static Control TextReplacementsDropDown(TextArea text) { var control = new Button { Text = "TextReplacements" }; control.Click += (sender, e) => { var replacements = text.TextReplacements; var supported = text.SupportedTextReplacements; var contextMenu = new ContextMenu(); foreach (var val in Enum.GetValues(typeof(TextReplacements)).OfType<TextReplacements>()) { if (val == TextReplacements.All || val == TextReplacements.None) { var item = new ButtonMenuItem { Text = val.ToString() }; item.Click += (sender2, e2) => text.TextReplacements = val; contextMenu.Items.Add(item); continue; } if (!supported.HasFlag(val)) continue; var checkItem = new CheckMenuItem { Text = val.ToString(), Checked = replacements.HasFlag(val) }; checkItem.CheckedChanged += (sender2, e2) => { var rep = text.TextReplacements; if (checkItem.Checked) rep |= val; else rep &= ~val; text.TextReplacements = rep; }; contextMenu.Items.Add(checkItem); } contextMenu.Show(control); }; return control; }
GridView WithContextMenuAndFilter() { var control = Default(); control.AllowMultipleSelection = true; var items = control.DataStore as DataStoreCollection; // Filter filterText.TextChanged += (s, e) => { var filterItems = (filterText.Text ?? "").Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); // Set the filter delegate on the GridView control.Filter = (filterItems.Length == 0) ? (Func<object, bool>)null : o => { var i = o as MyGridItem; var matches = true; // Every item in the split filter string should be within the Text property foreach (var filterItem in filterItems) if (i.Text.IndexOf(filterItem, StringComparison.CurrentCultureIgnoreCase) == -1) { matches = false; break; } return matches; }; }; // Context menu var menu = new ContextMenu(); var item = new ButtonMenuItem { Text = "Click Me!" }; item.Click += delegate { if (control.SelectedRows.Any()) Log.Write(item, "Click, Rows: {0}", SelectedRowsString(control)); else Log.Write(item, "Click, no item selected"); }; menu.Items.Add(item); // Delete menu item: deletes the item from the store, the UI updates via the binding. var deleteItem = new ButtonMenuItem { Text = "Delete Item" }; deleteItem.Click += (s, e) => { var i = control.SelectedItems.First() as MyGridItem; if (i != null) items.Remove(i); }; menu.Items.Add(deleteItem); // Insert item: inserts an item into the store, the UI updates via the binding. var insertItem = new ButtonMenuItem { Text = "Insert Item at the start of the list" }; insertItem.Click += (s, e) => { var i = control.SelectedItems.First() as MyGridItem; if (i != null) items.Insert(0, new MyGridItem(new Random(), 0, null)); }; menu.Items.Add(insertItem); control.ContextMenu = menu; return control; }
void Init() { //_buttonConnect _buttonConnect = new Button { Text = StrRes.GetString("StrConnect","Connect"), Image = Icons.ConnectIcon }; _buttonConnect.Click += ButtonConnect_Click; //_buttonDisconnect _buttonDisconnect = new Button { Text = StrRes.GetString("StrDisconnect","Disconnect"), Image = Icons.DisconnectIcon }; _buttonDisconnect.Click += _buttonDisconnect_Click; //_dropDownDbs _dropDownDbs = new DropDown {Width = 200}; //_buttonRunScript _buttonRunScript = new Button {Text = StrRes.GetString("StrExecute","Execute"), Image = Icons.RunScripIcon}; _buttonRunScript.Click += _buttonRunScript_Click; //_itemSaveAsCsv _itemSaveAsCsv = new ButtonMenuItem { Text = StrRes.GetString("StrSaveAsCsv","SaveAs .Csv") }; _itemSaveAsCsv.Click += _itemSaveAsCsv_Click; //_itemViewTable _itemViewTable = new ButtonMenuItem { Text = StrRes.GetString("StrViewTable","ViewTable") }; _itemViewTable.Click += _itemViewTable_Click; _itemViewTable.Enabled = false; //_itemCopyName _itemCopyName = new ButtonMenuItem { Text = StrRes.GetString("StrCopyName","CopyName") }; _itemCopyName.Click += _itemCopyName_Click; //_menuDbView _menuDbView = new ContextMenu(); _menuDbView.Items.Add(_itemCopyName); _menuDbView.Items.Add(_itemViewTable); //_menuResultView _menuResultView = new ContextMenu(); _menuResultView.Items.Add(_itemSaveAsCsv); //_treeViewDbs _treeViewDbs = new TreeView(); _treeViewDbs.ContextMenu = _menuDbView; _treeViewDbs.SelectionChanged += _treeViewDbs_SelectionChanged; _treeViewDbs.Activated += _treeViewDbs_Activated; _treeViewDbs.MouseUp += (sender, e) => { if (e.Buttons == MouseButtons.Alternate) { _treeViewDbs.ContextMenu.Show(_treeViewDbs); } }; //_textAreaSql _textAreaSql = new TextArea {Font = new Font(FontFamilies.Sans, 12, FontStyle.Bold | FontStyle.Italic)}; //_gridViewResult _gridViewResult = new GridView(); _gridViewResult.ContextMenu = _menuResultView; _gridViewResult.Style = "GridViewResult"; _gridViewResult.MouseUp += (sender, e) => { if (e.Buttons == MouseButtons.Alternate) { _gridViewResult.ContextMenu.Show(_treeViewDbs); } }; //topLayout var topLayout = new DynamicLayout(); topLayout.BeginHorizontal(); topLayout.AddCentered(_buttonConnect, horizontalCenter: false); topLayout.AddCentered(_buttonDisconnect, horizontalCenter: false); topLayout.AddCentered(_dropDownDbs, horizontalCenter: false); topLayout.AddCentered(_buttonRunScript, horizontalCenter: false); topLayout.Add(null); topLayout.EndVertical(); //rightPanel var rightPanel = new Splitter { Panel1 = _textAreaSql, Panel2 = _gridViewResult, Orientation = SplitterOrientation.Vertical, Position = 100 }; //mainLayout var mainLayout = new Splitter { Panel1 = _treeViewDbs, Panel2 = rightPanel, Orientation = SplitterOrientation.Horizontal, Position = 200 }; //layout var layout = new DynamicLayout { Padding = new Padding(0, 0), Spacing = new Size(5, 5) }; layout.AddRow(topLayout); layout.AddRow(mainLayout); Content = layout; }
Control ImagesAndMenu () { var control = new TreeGridView { Size = new Size (100, 150) }; control.Columns.Add (new GridColumn { DataCell = new ImageTextCell (0, 1), HeaderText = "Image and Text", AutoSize = true, Resizable = true, Editable = true }); control.Columns.Add (new GridColumn { DataCell = new TextBoxCell (2), HeaderText = "Text", AutoSize = true, Width = 150, Resizable = true, Editable = true }); #if DESKTOP var menu = new ContextMenu (); var item = new ImageMenuItem{ Text = "Click Me!"}; item.Click += delegate { if (control.SelectedItem != null) Log.Write (item, "Click, Rows: {0}", control.SelectedItem); else Log.Write (item, "Click, no item selected"); }; menu.MenuItems.Add (item); control.ContextMenu = menu; #endif control.DataStore = CreateComplexTreeItem (0, "", Image); LogEvents (control); return control; }
Control WithContextMenu () { var control = new ListBox { Size = new Size (100, 150) }; LogEvents (control); for (int i = 0; i < 10; i++) { control.Items.Add (new ListItem{ Text = "Item " + i }); } var menu = new ContextMenu (); var item = new ImageMenuItem{ Text = "Click Me!"}; item.Click += delegate { if (control.SelectedValue != null) Log.Write (item, "Click, Item: {0}", control.SelectedValue.Text); else Log.Write (item, "Click, no item selected"); }; menu.MenuItems.Add (item); control.ContextMenu = menu; return control; }
ContextMenu CreateContextMenu(GridView grid, SelectableFilterCollection<MyGridItem> filtered) { // Context menu var menu = new ContextMenu(); var item = new ButtonMenuItem { Text = "Click Me!" }; item.Click += (sender, e) => { if (grid.SelectedRows.Any()) Log.Write(item, "Click, Rows: {0}", SelectedRowsString(grid)); else Log.Write(item, "Click, no item selected"); }; menu.Items.Add(item); // Delete menu item: deletes the item from the store, the UI updates via the binding. var deleteItem = new ButtonMenuItem { Text = "Delete Item" }; deleteItem.Click += (s, e) => { var i = grid.SelectedItems.First() as MyGridItem; if (i != null) filtered.Remove(i); }; menu.Items.Add(deleteItem); // Insert item: inserts an item into the store, the UI updates via the binding. var insertItem = new ButtonMenuItem { Text = "Insert Item at the start of the list" }; insertItem.Click += (s, e) => { var i = grid.SelectedItems.First() as MyGridItem; if (i != null) filtered.Insert(0, new MyGridItem(new Random(), 0)); }; menu.Items.Add(insertItem); var subMenu = menu.Items.GetSubmenu("Sub Menu"); item = new ButtonMenuItem { Text = "Item 5" }; item.Click += (s, e) => Log.Write(item, "Clicked"); subMenu.Items.Add(item); item = new ButtonMenuItem { Text = "Item 6" }; item.Click += (s, e) => Log.Write(item, "Clicked"); subMenu.Items.Add(item); return menu; }
void Init() { //_textBoxUrl _textBoxUrl = new TextBox(); //_buttonReadFile _buttonReadFile = new Button { Text = StrRes.GetString("StrLoad", "Load") }; _buttonReadFile.Click += _buttonReadFile_Click; //_buttonSaveFile _buttonSaveFile = new Button {Text = StrRes.GetString("StrSave","Save")}; _buttonSaveFile.Click += _buttonSaveFile_Click; //_textAreaBody _textAreaBody = new TextArea(); //rightMenu_Body var rightMenuBody = new ContextMenu(); var findCommand = new Command { MenuText = StrRes.GetString("StrFind", "Find"), Shortcut = Keys.F | Application.Instance.CommonModifier }; findCommand.Executed += findCommand_Executed; rightMenuBody.Items.Add(findCommand); var layout = new DynamicLayout { Padding = new Padding(5, 5), Spacing = new Size(5, 5) }; layout.BeginVertical(); layout.BeginHorizontal(); layout.AddCentered(_textBoxUrl, xscale: true, horizontalCenter: false); layout.AddCentered(_buttonReadFile, horizontalCenter: false); layout.AddCentered(_buttonSaveFile, horizontalCenter: false); layout.EndBeginHorizontal(); layout.EndVertical(); layout.AddRow(_textAreaBody); // bug in gtk2 layout.ContextMenu = rightMenuBody; layout.MouseUp += (sender, e) => { if (e.Buttons == MouseButtons.Alternate) { layout.ContextMenu.Show(_textAreaBody); } }; Content = layout; }