private void OnCheckedChanged(object sender, EventArgs e) { // Are we allowed to process the event? if (!_ignoreEvents) { // Cast to the correct type KryptonCheckButton checkedButton = (KryptonCheckButton)sender; if (checkedButton.Checked) { // Uncheck the currently checked button if (_checkedButton != null) { // Prevent processing events caused by ourself _ignoreEvents = true; _checkedButton.Checked = false; _ignoreEvents = false; } // Remember the newly checked button _checkedButton = checkedButton; } else { // No check button is checked anymore _checkedButton = null; } // Generate event to show the value has changed OnCheckedButtonChanged(EventArgs.Empty); } }
private void KryptonCheckButtonCollectionForm_Load(object sender, EventArgs e) { // Get access to the container of the check set IContainer container = _checkSet.Container; // Assuming we manage to find a container if (container != null) { // Find all the check buttons inside the container foreach (object obj in container.Components) { // We are only interested in check buttons if (obj is KryptonCheckButton) { // Cast to the correct type KryptonCheckButton checkButton = (KryptonCheckButton)obj; // Add a new entry to the list box but only check it if // it is already present in the check buttons collection checkedListBox.Items.Add(new ListEntry(checkButton), _checkSet.CheckButtons.Contains(checkButton)); } } } }
private void CheckButtonAdded(KryptonCheckButton checkButton) { // If the incoming button is already checked if (checkButton.Checked) { // If we already have a button checked if (_checkedButton != null) { // Then uncheck the incoming button checkButton.Checked = false; } else { // Remember this as the currently checked instance _checkedButton = checkButton; // Generate event to show the value has changed OnCheckedButtonChanged(EventArgs.Empty); } } // Need to monitor and control the change of checked state checkButton.CheckedChanging += new CancelEventHandler(OnCheckedChanging); checkButton.CheckedChanged += new EventHandler(OnCheckedChanged); }
/// <summary> /// Initialize a new instance of the KryptonCheckButtonActionList class. /// </summary> /// <param name="owner">Designer that owns this action list instance.</param> public KryptonCheckButtonActionList(KryptonCheckButtonDesigner owner) : base(owner) { // Remember the button instance _checkButton = owner.Component as KryptonCheckButton; // Assuming we were correctly passed an actual component... if (_checkButton != null) { // Get access to the actual Orientation propertry PropertyDescriptor checkedProp = TypeDescriptor.GetProperties(_checkButton)["Checked"]; // If we succeeded in getting the property if (checkedProp != null) { // Decide on the next action to take given the current setting if ((bool)checkedProp.GetValue(_checkButton)) { _action = "Uncheck the button"; } else { _action = "Check the button"; } } } // Cache service used to notify when a property has changed _service = (IComponentChangeService)GetService(typeof(IComponentChangeService)); }
private void OnCheckedChanging(object sender, CancelEventArgs e) { // Are we allowed to process the event? if (!_ignoreEvents) { // Cast to the correct type KryptonCheckButton checkedButton = (KryptonCheckButton)sender; // Prevent the checked button becoming unchecked unless AllowUncheck is defined e.Cancel = checkedButton.Checked && !AllowUncheck; } }
private void CheckButtonRemoved(KryptonCheckButton checkButton) { // Unhook from monitoring events checkButton.CheckedChanging -= new CancelEventHandler(OnCheckedChanging); checkButton.CheckedChanged -= new EventHandler(OnCheckedChanged); // If the removed button is the currently checked one if (_checkedButton == checkButton) { // Then we no longer have a currently checked button _checkedButton = null; // Generate event to show the value has changed OnCheckedButtonChanged(EventArgs.Empty); } }
/// <summary> /// Removes a KryptonCheckButton from the collection. /// </summary> /// <param name="checkButton">The KryptonCheckButton to remove.</param> public void Remove(KryptonCheckButton checkButton) { Debug.Assert(checkButton != null); if (checkButton == null) { throw new ArgumentNullException("checkButton"); } if (!Contains(checkButton)) { throw new ArgumentException("No matching reference to remove"); } base.List.Remove(checkButton); }
/// <summary> /// Adds the specifies KryptonCheckButton to the collection. /// </summary> /// <param name="checkButton">The KryptonCheckButton object to add to the collection.</param> /// <returns>The index of the new entry.</returns> public int Add(KryptonCheckButton checkButton) { Debug.Assert(checkButton != null); if (checkButton == null) { throw new ArgumentNullException("checkButton"); } if (Contains(checkButton)) { throw new ArgumentException("Reference already exists in the collection"); } base.List.Add(checkButton); return(base.List.Count - 1); }
/// <summary> /// Inserts a KryptonCheckButton reference into the collection at the specified location. /// </summary> /// <param name="index">Index of position to insert.</param> /// <param name="checkButton">The KryptonCheckButton reference to insert.</param> public void Insert(int index, KryptonCheckButton checkButton) { Debug.Assert(checkButton != null); if (checkButton == null) { throw new ArgumentNullException("checkButton"); } if ((index < 0) || (index > Count)) { throw new ArgumentOutOfRangeException("index"); } if (Contains(checkButton)) { throw new ArgumentException("Reference already in collection"); } base.List.Insert(index, checkButton); }
/// <summary> /// Determines whether a KryptonCheckButton is in the collection. /// </summary> /// <param name="checkButton">The KryptonCheckButton to locate in the collection.</param> /// <returns>True if found in collection; otherwise false.</returns> public bool Contains(KryptonCheckButton checkButton) { return(base.List.Contains(checkButton)); }
/// <summary> /// Returns the index of the KryptonCheckButton reference. /// </summary> /// <param name="checkButton">The KryptonCheckButton to locate.</param> /// <returns>Index of reference; otherwise -1.</returns> public int IndexOf(KryptonCheckButton checkButton) { return(base.List.IndexOf(checkButton)); }
/// <summary> /// Initialize a new instance of the ListEntry class. /// </summary> /// <param name="checkButton">CheckButton to encapsulate.</param> public ListEntry(KryptonCheckButton checkButton) { Debug.Assert(checkButton != null); _checkButton = checkButton; }