/// <summary> /// Raises the <see cref="E:System.Windows.Forms.Control.ControlAdded"></see> event. /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.ControlEventArgs"></see> that contains the event data.</param> protected override void OnControlAdded(ControlEventArgs e) { base.OnControlAdded(e); NuGenSwitchButton switchButton = e.Control as NuGenSwitchButton; if (switchButton != null) { _switchButtons.Add(switchButton); this.InitializeSwitchButton(switchButton); } }
/// <summary> /// Raises the <see cref="E:System.Windows.Forms.Control.ControlRemoved"></see> event. /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.ControlEventArgs"></see> that contains the event data.</param> protected override void OnControlRemoved(ControlEventArgs e) { base.OnControlRemoved(e); NuGenSwitchButton switchButton = e.Control as NuGenSwitchButton; if (switchButton != null) { _switchButtons.Remove(switchButton); this.ResetSwitchButton(switchButton); } }
private void InitializeSwitchButton(NuGenSwitchButton switchButton) { Debug.Assert(switchButton != null, "switchButton != null"); this.SetSwitchButtonDockStyle(switchButton, this.Orientation); switchButton.Click += _switchButton_Click; switchButton.ImageAlign = this.SwitchButtonImageAlign; switchButton.Orientation = this.Orientation; switchButton.TextAlign = this.SwitchButtonTextAlign; switchButton.Size = this.SwitchButtonSize; this.SelectedSwitchButton = switchButton; switchButton.BringToFront(); }
private void SetSwitchButtonDockStyle(NuGenSwitchButton switchButton, NuGenOrientationStyle orientation) { Debug.Assert(switchButton != null, "switchButton != null"); switchButton.Orientation = orientation; if (orientation == NuGenOrientationStyle.Horizontal) { switchButton.Dock = DockStyle.Left; } else { switchButton.Dock = DockStyle.Top; } }
/* * InitializeSwitchButton */ private void InitializeSwitchButton(NuGenSwitchButton switchButtonToInitialize) { Debug.Assert(switchButtonToInitialize != null, "switchButtonToInitialize != null"); switchButtonToInitialize.Click += _switchButton_Click; switchButtonToInitialize.DoubleClick += _switchButton_DoubleClick; switchButtonToInitialize.DragDrop += _switchButton_DragDrop; switchButtonToInitialize.DragEnter += _switchButton_DragEnter; switchButtonToInitialize.DragLeave += _switchButton_DragLeave; switchButtonToInitialize.MouseDown += _switchButton_MouseDown; switchButtonToInitialize.MouseEnter += _switchButton_MouseEnter; switchButtonToInitialize.MouseHover += _switchButton_MouseHover; switchButtonToInitialize.MouseLeave += _switchButton_MouseLeave; switchButtonToInitialize.MouseUp += _switchButton_MouseUp; }
/* * RemoveSwitchButton */ private void RemoveSwitchButton(NuGenSwitchButton switchButtonToRemove) { Debug.Assert(switchButtonToRemove != null, "switchButtonToRemove != null"); Debug.Assert(_switchPanel != null, "_switchPanel != null"); switchButtonToRemove.Click -= _switchButton_Click; switchButtonToRemove.DoubleClick -= _switchButton_DoubleClick; switchButtonToRemove.DragDrop -= _switchButton_DragDrop; switchButtonToRemove.DragEnter -= _switchButton_DragEnter; switchButtonToRemove.DragLeave -= _switchButton_DragLeave; switchButtonToRemove.MouseDown -= _switchButton_MouseDown; switchButtonToRemove.MouseEnter -= _switchButton_MouseEnter; switchButtonToRemove.MouseHover -= _switchButton_MouseHover; switchButtonToRemove.MouseLeave -= _switchButton_MouseLeave; switchButtonToRemove.MouseUp -= _switchButton_MouseUp; _switchPanel.Controls.Remove(switchButtonToRemove); }
/* * RemoveSwitchPage */ private void RemoveSwitchPage(NuGenSwitchPage switchPageToRemove) { Debug.Assert(switchPageToRemove != null, "switchPageToRemove != null"); Debug.Assert(_buttonPageDictionary != null, "_buttonPageDictionary != null"); Debug.Assert(_pageButtonDictionary != null, "_pageButtonDictionary != null"); NuGenSwitchButton associatedSwitchButton = _pageButtonDictionary[switchPageToRemove]; Debug.Assert(associatedSwitchButton != null, "associatedSwitchButton != null"); switchPageToRemove.EnabledChanged -= _switchPage_EnabledChanged; switchPageToRemove.SwitchButtonImageChanged -= _switchPage_SwitchButtonImageChanged; switchPageToRemove.TextChanged -= _switchPage_TextChanged; _buttonPageDictionary.Remove(associatedSwitchButton); _pageButtonDictionary.Remove(switchPageToRemove); this.RemoveSwitchButton(associatedSwitchButton); }
private void _switchPage_EnabledChanged(object sender, EventArgs e) { Debug.Assert(sender is NuGenSwitchPage, "sender is NuGenSwitchPage"); NuGenSwitchPage switchPage = (NuGenSwitchPage)sender; Debug.Assert(_pageButtonDictionary != null, "_pageButtonDictionary != null"); Debug.Assert(_pageButtonDictionary.ContainsKey(switchPage), "_pageButtonDictionary.ContainsKey(switchPage)"); NuGenSwitchButton switchButton = _pageButtonDictionary[switchPage]; switchButton.Enabled = switchPage.Enabled; switchButton.Invalidate(); if ( !switchPage.Enabled && switchPage == this.SelectedSwitchPage ) { NuGenSwitchPage newSelectedSwitchPage = null; for (int i = this.SelectedIndex - 1; i > -1; i--) { if (this.SwitchPages[i].Enabled) { newSelectedSwitchPage = this.SwitchPages[i]; } } if (newSelectedSwitchPage == null) { for (int i = this.SelectedIndex + 1; i < this.SwitchPages.Count; i++) { if (this.SwitchPages[i].Enabled) { newSelectedSwitchPage = this.SwitchPages[i]; } } } this.SelectedSwitchPage = newSelectedSwitchPage; } }
/// <summary> /// </summary> /// <param name="pointToTest">Screen coordinates expected.</param> public NuGenSwitcherHitResult HitTest(Point pointToTest) { Point cp = this.PointToClient(pointToTest); if (this.ClientRectangle.Contains(cp)) { foreach (Control ctrl in this.Controls) { NuGenSwitchButton switchButton = ctrl as NuGenSwitchButton; if (switchButton != null && switchButton.Bounds.Contains(cp)) { return(NuGenSwitcherHitResult.SwitchButtons); } } return(NuGenSwitcherHitResult.SwitchPanel); } return(NuGenSwitcherHitResult.Nowhere); }
/* * InitializeSwitchPage */ private NuGenSwitchButton InitializeSwitchPage(NuGenSwitchPage switchPageToInitialize) { Debug.Assert(switchPageToInitialize != null, "switchPageToInitialize != null"); Debug.Assert(this.ServiceProvider != null, "this.ServiceProvider != null"); NuGenSwitchButton switchButtonToAssociate = new NuGenSwitchButton(this.ServiceProvider); switchButtonToAssociate.Image = switchPageToInitialize.SwitchButtonImage; switchButtonToAssociate.Text = switchPageToInitialize.Text; Debug.Assert(_buttonPageDictionary != null, "_buttonPageDictionary != null"); Debug.Assert(_pageButtonDictionary != null, "_pageButtonDictionary != null"); _buttonPageDictionary.Add(switchButtonToAssociate, switchPageToInitialize); _pageButtonDictionary.Add(switchPageToInitialize, switchButtonToAssociate); switchPageToInitialize.EnabledChanged += _switchPage_EnabledChanged; switchPageToInitialize.SwitchButtonImageChanged += _switchPage_SwitchButtonImageChanged; switchPageToInitialize.TextChanged += _switchPage_TextChanged; this.Controls.Add(switchPageToInitialize); switchPageToInitialize.BringToFront(); return(switchButtonToAssociate); }
/* * AddSwitchButton */ private void AddSwitchButton(NuGenSwitchButton switchButtonToAdd) { Debug.Assert(switchButtonToAdd != null, "switchButtonToAdd != null"); Debug.Assert(_switchPanel != null, "_switchPanel != null"); _switchPanel.Controls.Add(switchButtonToAdd); this.InitializeSwitchButton(switchButtonToAdd); }
private void ResetSwitchButton(NuGenSwitchButton switchButton) { Debug.Assert(switchButton != null, "switchButton != null"); switchButton.Click -= _switchButton_Click; if (_switchButtons.Count > 0) { this.SelectedSwitchButton = _switchButtons[_switchButtons.Count - 1]; } }
/* * InitializeSwitchPage */ private NuGenSwitchButton InitializeSwitchPage(NuGenSwitchPage switchPageToInitialize) { Debug.Assert(switchPageToInitialize != null, "switchPageToInitialize != null"); Debug.Assert(this.ServiceProvider != null, "this.ServiceProvider != null"); NuGenSwitchButton switchButtonToAssociate = new NuGenSwitchButton(this.ServiceProvider); switchButtonToAssociate.Image = switchPageToInitialize.SwitchButtonImage; switchButtonToAssociate.Text = switchPageToInitialize.Text; Debug.Assert(_buttonPageDictionary != null, "_buttonPageDictionary != null"); Debug.Assert(_pageButtonDictionary != null, "_pageButtonDictionary != null"); _buttonPageDictionary.Add(switchButtonToAssociate, switchPageToInitialize); _pageButtonDictionary.Add(switchPageToInitialize, switchButtonToAssociate); switchPageToInitialize.EnabledChanged += _switchPage_EnabledChanged; switchPageToInitialize.SwitchButtonImageChanged += _switchPage_SwitchButtonImageChanged; switchPageToInitialize.TextChanged += _switchPage_TextChanged; this.Controls.Add(switchPageToInitialize); switchPageToInitialize.BringToFront(); return switchButtonToAssociate; }
/* * InsertSwitchButton */ private void InsertSwitchButton(int index, NuGenSwitchButton switchButtonToInsert) { Debug.Assert(switchButtonToInsert != null, "switchButtonToInsert != null"); this.Controls.Add(switchButtonToInsert); this.InitializeSwitchButton(switchButtonToInsert); }
/// <summary> /// Initializes a new instance of the <see cref="NuGenFontBlock"/> class. /// </summary> /// <param name="serviceProvider"> /// <para><see cref="INuGenButtonStateService"/></para> /// <para><see cref="INuGenControlStateService"/></para> /// <para><see cref="INuGenComboBoxRenderer"/></para> /// <para><see cref="INuGenImageListService"/></para> /// <para><see cref="INuGenFontFamiliesProvider"/></para> /// <para><see cref="INuGenSwitchButtonLayoutManager"/></para> /// <para><see cref="INuGenSwitchButtonRenderer"/></para> /// </param> /// <exception cref="ArgumentNullException"> /// <para><paramref name="serviceProvider"/> is <see langword="null"/>.</para> /// </exception> public NuGenFontBlock(INuGenServiceProvider serviceProvider) : base(serviceProvider) { _spacers = new NuGenSpacer[4]; for (int i = 0; i < _spacers.Length; i++) { _spacers[i] = new NuGenSpacer(); _spacers[i].Dock = DockStyle.Right; _spacers[i].Width = 3; } _fontBox = new NuGenFontBox(serviceProvider); _fontBox.Dock = DockStyle.Fill; _fontSizeBox = new NuGenFontSizeBox(serviceProvider); _fontSizeBox.Dock = DockStyle.Right; _fontSizeBox.Width = 50; _boldButton = new NuGenSwitchButton(serviceProvider); _italicButton = new NuGenSwitchButton(serviceProvider); _underlineButton = new NuGenSwitchButton(serviceProvider); _boldButton.Size = _italicButton.Size = _underlineButton.Size = new Size(21, 21); _boldButton.Dock = _italicButton.Dock = _underlineButton.Dock = DockStyle.Right; _boldButton.CheckOnClick = _italicButton.CheckOnClick = _underlineButton.CheckOnClick = true; _boldButton.Text = Resources.Text_FontBlock_Bold; _italicButton.Text = Resources.Text_FontBlock_Italic; _underlineButton.Text = Resources.Text_FontBlock_Underline; _fontBox.SelectedIndexChanged += _selectedFont_StyleChanged; _fontSizeBox.ValueChanged += _selectedFont_StyleChanged; _boldButton.CheckedChanged += _selectedFont_StyleChanged; _italicButton.CheckedChanged += _selectedFont_StyleChanged; _underlineButton.CheckedChanged += _selectedFont_StyleChanged; this.Controls.AddRange( new Control[] { _fontBox , _spacers[0] , _fontSizeBox , _spacers[1] , _boldButton , _spacers[2] , _italicButton , _spacers[3] , _underlineButton } ); }