//=------------------------------------------------------------------= // customizeToolStrip1_SelectedToolStripChanged //=------------------------------------------------------------------= /// <summary> /// This is fired whenever the selected ToolStrip changes in the /// "Toolbar/Menu" ComboBox, as well as when the dialog is first /// shown. /// </summary> /// /// <param name="sender"> /// The CustomizeToolStrip component from whence this event comes. /// </param> /// /// <param name="ctsea"> /// The CustomizeToolStripAvailableEventArgs event information /// object. Upon exiting, we need to set the AvailableItems /// Property of this object to contain the list of buttons we want /// shown. /// </param> /// private void customizeToolStrip1_SelectedToolStripChanged ( object sender, CustomizeToolStripAvailableEventArgs ctsea) { System.Reflection.FieldInfo[] fields; ArrayList al = new ArrayList(); // // okay, instead of maintaining a huge array of buttons that could // change every time we update the sample, we're just going to go // and look at ALL of our member variables and just include those // that are of a type that we would include in a ToolStrip, // notably buttons, dropdowns, combobox, labels, textbox, and split // buttons. // // // we'll first use reflect to get our member variables. // fields = typeof(Form1).GetFields(BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance); // // For each field on our object, see if it's the right type, // and if so, include it. // for (int x = 0; x < fields.Length; x++) { Type t; t = fields[x].FieldType; if (t == typeof(ToolStripButton) || t == typeof(ToolStripSeparator) || t == typeof(ToolStripComboBox) || t == typeof(ToolStripDropDownButton) || t == typeof(ToolStripLabel) || t == typeof(ToolStripTextBox) || t == typeof(ToolStripSplitButton)) { al.Add(fields[x].GetValue(this)); } } // // cast the array to the right type and return it. // ctsea.AvailableItems = (ToolStripItem[])al.ToArray(typeof(ToolStripItem)); }
//=------------------------------------------------------------------= // customizeToolStrip1_SelectedToolStripChanged //=------------------------------------------------------------------= /// <summary> /// This is fired whenever the selected ToolStrip changes in the /// "Toolbar/Menu" ComboBox, as well as when the dialog is first /// shown. /// </summary> /// /// <param name="sender"> /// The CustomizeToolStrip component from whence this event comes. /// </param> /// /// <param name="ctsea"> /// The CustomizeToolStripAvailableEventArgs event information /// object. Upon exiting, we need to set the AvailableItems /// Property of this object to contain the list of buttons we want /// shown. /// </param> /// private void customizeToolStrip1_SelectedToolStripChanged ( object sender, CustomizeToolStripAvailableEventArgs ctsea) { System.Reflection.FieldInfo[] fields; ArrayList al = new ArrayList(); // // okay, instead of maintaining a huge array of buttons that could // change every time we update the sample, we're just going to go // and look at ALL of our member variables and just include those // that are of a type that we would include in a ToolStrip, // notably buttons, dropdowns, bombox, labels, textbox, and split // buttons. // // // we'll first use reflect to get our member variables. // fields = typeof(Form1).GetFields(BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance); // // for each field on our object, see if it's the right type, and // if so, include that puppy! // for (int x = 0; x < fields.Length; x++) { Type t; t = fields[x].FieldType; if (t == typeof(ToolStripButton) || t == typeof(ToolStripSeparator) || t == typeof(ToolStripComboBox) || t == typeof(ToolStripDropDownButton) || t == typeof(ToolStripLabel) || t == typeof(ToolStripTextBox) || t == typeof(ToolStripSplitButton)) { al.Add(fields[x].GetValue(this)); } } // // cast the array to the right type and return it. // ctsea.AvailableItems = (ToolStripItem[])al.ToArray(typeof(ToolStripItem)); }