public static ToolStripButton click(this ToolStripButton button) { return(button.toolStrip().invokeOnThread( () => { button.PerformClick(); return button; })); }
} //Todo: refactor with one below public static ToolStripButton add_Button(this ToolStrip toolStrip, string text, string resourceName, Image image, Action onClick) { if (toolStrip.isNull()) { "[ToolStripButton][add_Button] provided toolStrip was null".error(); return(null); } return(toolStrip.invokeOnThread( () => { var button = new ToolStripButton(); toolStrip.Items.Add(button); try { if (resourceName.valid()) { button.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText; button.applyResources(resourceName); } if (image.notNull()) { button.Image = image; } if (text.valid()) { button.Text = text; } button.Click += (sender, e) => { if (onClick.notNull()) { onClick(); } }; } catch (Exception ex) { ex.log("inside toolStrip add_Button"); } Application.DoEvents(); if (button.toolStrip() != toolStrip) { "[ToolStripButton][add_Button] parent was not set, so setting it manuallly".error(); //button.prop("Parent", toolStrip); Reflection_ExtensionMethods_Properties.prop("button", "Parent", toolStrip); } return button; })); }