private void SetupSortButton(ref ToolStripButton button, ToolStrip owner, int index, PropertySort sort) { button = owner.Items[index] as ToolStripButton; if (button != null) { var events = button.GetType().GetProperty(nameof(Events), BindingFlags.NonPublic | BindingFlags.Instance).GetValue(button) as EventHandlerList; var head = events.GetType().GetField("head", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(events); var key = head.GetType().GetField("key", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(head); var handler = head.GetType().GetField("handler", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(head) as Delegate; events.RemoveHandler(key, handler); button.Tag = sort; button.Click += (s_, e_) => { var b = s_ as ToolStripButton; if (b.Tag is PropertySort s) { b.Checked = !b.Checked; if (b.Checked) { PropertySort |= s; } else { PropertySort &= ~s; } RefreshDatasouce(); } SetSortButtonsState(); }; } }
private void ToLow() { foreach (ToolStripItem TSI in toolStrip1.Items) { ToolStripButton TSS = new ToolStripButton(); if (TSI.GetType() == TSS.GetType()) { ToolStripButton TB = (ToolStripButton)TSI; TB.Text = TB.Text.ToLower(); } } foreach (ToolStripItem TSI in toolStrip2.Items) { ToolStripButton TSS = new ToolStripButton(); if (TSI.GetType() == TSS.GetType()) { ToolStripButton TB = (ToolStripButton)TSI; TB.Text = TB.Text.ToLower(); } } foreach (ToolStripItem TSI in toolStrip3.Items) { ToolStripButton TSS = new ToolStripButton(); if (TSI.GetType() == TSS.GetType()) { ToolStripButton TB = (ToolStripButton)TSI; TB.Text = TB.Text.ToLower(); } } }
private void RemoveClickEvent(ToolStripButton b) { FieldInfo f1 = typeof(Control).GetField("EventClick", BindingFlags.Static | BindingFlags.NonPublic); object obj = f1.GetValue(b); PropertyInfo pi = b.GetType().GetProperty("Events", BindingFlags.NonPublic | BindingFlags.Instance); EventHandlerList list = (EventHandlerList)pi.GetValue(b, null); list.RemoveHandler(obj, list[obj]); }
static string GetToolStripButtonState(ToolStripButton button) { return(button.GetType().ToString() + ":" + (button.Checked == true ? "yes" : "no")); }