/// <summary> /// Handle mouse down over a button on the customisation panel. /// </summary> private void CustomizePanelOnMouseDown(object sender, MouseEventArgs mouseEventArgs) { CRRoundButton button = sender as CRRoundButton; if (button != null) { // Make a copy of the item being dragged. ToolbarDataItem item = (ToolbarDataItem)button.Tag; _draggedButton = new CRToolbarItem(item) { Control = button }; _hasDragItem = false; _dragSource = null; } }
/// <summary> /// Update all the search bar buttons when the selected forum or /// topic changes. /// </summary> private void UpdateSearchBarButtons() { if (_searchBar != null && _searchBarVisible) { const int yPosition = 4; int xPosition = 4; _searchBar.Controls.Clear(); _searchBar.SuspendLayout(); string topicName = null; string forumName; FolderBase forumFolder; FolderBase topicFolder; TreeNode currentNode = frmList.SelectedNode; if (currentNode.Parent != null) { forumName = currentNode.Parent.Text; topicName = currentNode.Text; forumFolder = currentNode.Parent.Tag as FolderBase; topicFolder = currentNode.Tag as FolderBase; } else { forumName = currentNode.Text; forumFolder = currentNode.Tag as FolderBase; topicFolder = null; } CRRoundButton currentForumSearchButton = new CRRoundButton { Name = _currentForumSearchButton, Text = forumName, CanHaveFocus = true, AutoSize = true, Parent = _searchBar, ExtraData = forumFolder, Location = new Point(xPosition, yPosition) }; currentForumSearchButton.Click += SearchButtonOnClick; _searchBar.Controls.Add(currentForumSearchButton); ToolTip newToolTip = new ToolTip(); newToolTip.SetToolTip(currentForumSearchButton, Resources.CurrentForumSearch); if (topicName != null) { xPosition += currentForumSearchButton.Width + 8; CRRoundButton currentTopicSearchButton = new CRRoundButton { Name = _currentTopicSearchButton, Text = topicName, CanHaveFocus = true, AutoSize = true, Parent = _searchBar, ExtraData = topicFolder, Location = new Point(xPosition, yPosition) }; currentTopicSearchButton.Click += SearchButtonOnClick; _searchBar.Controls.Add(currentTopicSearchButton); newToolTip = new ToolTip(); newToolTip.SetToolTip(currentTopicSearchButton, Resources.CurrentTopicSearch); } PictureBox sbClose = new PictureBox { Anchor = AnchorStyles.Top | AnchorStyles.Right, Image = Resources.CloseButton, Location = new Point(_searchBar.Right - 36, 4), Name = "sbClose", Parent = _searchBar, Size = new Size(24, 24), TabIndex = 4, TabStop = false }; sbClose.Click += OnSearchBarClose; _searchBar.Controls.Add(sbClose); newToolTip = new ToolTip(); newToolTip.SetToolTip(sbClose, Resources.CloseSearchBar); _searchBar.ResumeLayout(false); } }
/// <summary> /// Internal customisation logic /// </summary> private void InternalCustomiseToolbar() { const int formWidth = 600; const int formHeight = 200; Point pos = PointToScreen(new Point((Width - formWidth) / 2, Bottom - Top)); _customPanel = new Form { Size = new Size(formWidth, formHeight), FormBorderStyle = FormBorderStyle.FixedSingle, MinimizeBox = false, MaximizeBox = false, ControlBox = false, Dock = DockStyle.Fill, BackColor = SystemColors.Window, AutoScaleDimensions = new SizeF(6F, 13F), AutoScaleMode = AutoScaleMode.Font, StartPosition = FormStartPosition.Manual, ShowIcon = false, ShowInTaskbar = false, Text = String.Empty, Location = pos }; CRToolbarItemCollection collection = CRToolbarItemCollection.DefaultCollection; // Populate the panel with all possible buttons. IEnumerable<ToolbarDataItem> allButtons = collection.AllButtons; int xPosition = 10; int yPosition = 20; int nextYPosition = 20; int buttonHeight = Height - 12; int buttonWidth = Height - 6; const int spacing = 14; foreach (ToolbarDataItem item in allButtons) { int itemWidth = (item.Type == CRToolbarItemType.Search) ? (item.Image.Width + 12) : buttonWidth; SizeF sizeF = CreateGraphics().MeasureString(item.label, Font); int realWidth = Math.Max((int)sizeF.Width, itemWidth); CRRoundButton newButton = new CRRoundButton { Image = item.Image, Location = new Point(xPosition + (realWidth - itemWidth) / 2, yPosition), Name = item.name, Text = String.Empty, Enabled = true, Parent = _customPanel, Size = new Size(itemWidth, buttonHeight), Tag = item, ImageScaling = true }; newButton.MouseDown += CustomizePanelOnMouseDown; newButton.MouseMove += CustomisationOnMouseMove; newButton.MouseUp += CustomisationOnMouseUp; _customPanel.Controls.Add(newButton); Label newButtonLabel = new Label { Text = item.label, AutoSize = true, Location = new Point((realWidth - (int)sizeF.Width) / 2 + xPosition, yPosition + buttonHeight + 4) }; _customPanel.Controls.Add(newButtonLabel); xPosition += realWidth + spacing; nextYPosition = Math.Max(nextYPosition, yPosition + newButton.Height + newButtonLabel.Height + spacing + 4); if (xPosition > _customPanel.ClientRectangle.Right - itemWidth) { xPosition = spacing; yPosition = nextYPosition; } } const int mainButtonWidth = 80; const int mainButtonHeight = 23; // Adjust height if necessary _customPanel.Height = nextYPosition + mainButtonHeight + 8; // Close button in bottom right Button closeButton = new Button { Size = new Size(mainButtonWidth, mainButtonHeight), Text = Resources.Close, Visible = true, Enabled = true, Parent = _customPanel, BackColor = SystemColors.ButtonFace, Location = new Point((_customPanel.ClientRectangle.Width - mainButtonWidth) - 4, (_customPanel.ClientRectangle.Height - mainButtonHeight) - 4) }; closeButton.Click += CloseButtonOnClick; _customPanel.Controls.Add(closeButton); // Reset button in bottom right Button resetButton = new Button { Size = new Size(mainButtonWidth, mainButtonHeight), Text = Resources.Reset, Visible = true, Enabled = true, Parent = _customPanel, BackColor = SystemColors.ButtonFace, Location = new Point((closeButton.Left - (mainButtonWidth + 4)) - 4, (_customPanel.ClientRectangle.Height - mainButtonHeight) - 4) }; resetButton.Click += ResetButtonOnClick; _customPanel.Controls.Add(resetButton); // Enable all the toolbar buttons so they're draggable foreach (CRRoundButton button in (from item in collection.Buttons where item.Type == CRToolbarItemType.Button select item.Control).OfType<CRRoundButton>()) { button.Enabled = true; } // Make sure the separators are visible foreach (CRToolbarItem item in collection.Buttons.Where(item => item.Type == CRToolbarItemType.Space || item.Type == CRToolbarItemType.FlexibleSpace)) { item.Control.Visible = true; } // Animate the customise bar into view. The following two lines are to ensure that the // dialog controls are rendered before they appear. _customPanel.Show(); _customPanel.Hide(); Platform.AnimateWindowIn(_customPanel.Handle); _customPanel.Show(this); // Flag we're in customisation mode Customising = true; }
/// <summary> /// Load and initialise the toolbar. /// </summary> public void Load() { bool hasSearchField = false; int buttonHeight = Height - 12; int buttonWidth = Height - 6; SuspendLayout(); Controls.Clear(); foreach (CRToolbarItem button in CRToolbarItemCollection.DefaultCollection.Buttons) { switch (button.Type) { case CRToolbarItemType.Search: if (!hasSearchField) { CRSearchField searchField = new CRSearchField { Size = new Size(buttonWidth, buttonHeight), Text = String.Empty, Visible = true }; button.Control = searchField; searchField.Tag = button; searchField.MouseDown += ToolbarOnMouseDown; searchField.MouseMove += CustomisationOnMouseMove; Controls.Add(searchField); // Can only have one search field hasSearchField = true; } break; case CRToolbarItemType.Button: { CRRoundButton newButton = new CRRoundButton { Image = button.Image, Name = button.Name, Text = String.Empty, Size = new Size(buttonWidth, buttonHeight), ImageScaling = true, Enabled = (button.ID == ActionID.Script || Customising) }; newButton.Click += OnToolbarItemClick; newButton.MouseDown += ToolbarOnMouseDown; newButton.MouseMove += CustomisationOnMouseMove; button.Control = newButton; Controls.Add(newButton); newButton.Tag = button; // Add a tooltip for this button ToolTip newToolTip = new ToolTip(); newToolTip.SetToolTip(newButton, button.Tooltip); break; } case CRToolbarItemType.FlexibleSpace: case CRToolbarItemType.Space: { PictureBox pictureBox = new PictureBox { Name = button.Name, Size = new Size(buttonWidth, buttonHeight), Visible = Customising }; button.Control = pictureBox; pictureBox.Tag = button; pictureBox.MouseDown += ToolbarOnMouseDown; pictureBox.MouseMove += CustomisationOnMouseMove; Controls.Add(pictureBox); break; } } } Relayout(); ResumeLayout(true); }
/// <summary> /// Internal customisation logic /// </summary> private void InternalCustomiseToolbar() { const int formWidth = 600; const int formHeight = 200; Point pos = PointToScreen(new Point((Width - formWidth) / 2, Bottom - Top)); _customPanel = new Form { Size = new Size(formWidth, formHeight), FormBorderStyle = FormBorderStyle.FixedSingle, MinimizeBox = false, MaximizeBox = false, ControlBox = false, Dock = DockStyle.Fill, BackColor = SystemColors.Window, AutoScaleDimensions = new SizeF(6F, 13F), AutoScaleMode = AutoScaleMode.Font, StartPosition = FormStartPosition.Manual, ShowIcon = false, ShowInTaskbar = false, Text = String.Empty, Location = pos }; CRToolbarItemCollection collection = CRToolbarItemCollection.DefaultCollection; // Populate the panel with all possible buttons. IEnumerable <ToolbarDataItem> allButtons = collection.AllButtons; int xPosition = 10; int yPosition = 20; int nextYPosition = 20; int buttonHeight = Height - 12; int buttonWidth = Height - 6; const int spacing = 14; foreach (ToolbarDataItem item in allButtons) { int itemWidth = (item.Type == CRToolbarItemType.Search) ? (item.Image.Width + 12) : buttonWidth; SizeF sizeF = CreateGraphics().MeasureString(item.label, Font); int realWidth = Math.Max((int)sizeF.Width, itemWidth); CRRoundButton newButton = new CRRoundButton { Image = item.Image, Location = new Point(xPosition + (realWidth - itemWidth) / 2, yPosition), Name = item.name, Text = String.Empty, Enabled = true, Parent = _customPanel, Size = new Size(itemWidth, buttonHeight), Tag = item, ImageScaling = true }; newButton.MouseDown += CustomizePanelOnMouseDown; newButton.MouseMove += CustomisationOnMouseMove; newButton.MouseUp += CustomisationOnMouseUp; _customPanel.Controls.Add(newButton); Label newButtonLabel = new Label { Text = item.label, AutoSize = true, Location = new Point((realWidth - (int)sizeF.Width) / 2 + xPosition, yPosition + buttonHeight + 4) }; _customPanel.Controls.Add(newButtonLabel); xPosition += realWidth + spacing; nextYPosition = Math.Max(nextYPosition, yPosition + newButton.Height + newButtonLabel.Height + spacing + 4); if (xPosition > _customPanel.ClientRectangle.Right - itemWidth) { xPosition = spacing; yPosition = nextYPosition; } } const int mainButtonWidth = 80; const int mainButtonHeight = 23; // Adjust height if necessary _customPanel.Height = nextYPosition + mainButtonHeight + 8; // Close button in bottom right Button closeButton = new Button { Size = new Size(mainButtonWidth, mainButtonHeight), Text = Resources.Close, Visible = true, Enabled = true, Parent = _customPanel, BackColor = SystemColors.ButtonFace, Location = new Point((_customPanel.ClientRectangle.Width - mainButtonWidth) - 4, (_customPanel.ClientRectangle.Height - mainButtonHeight) - 4) }; closeButton.Click += CloseButtonOnClick; _customPanel.Controls.Add(closeButton); // Reset button in bottom right Button resetButton = new Button { Size = new Size(mainButtonWidth, mainButtonHeight), Text = Resources.Reset, Visible = true, Enabled = true, Parent = _customPanel, BackColor = SystemColors.ButtonFace, Location = new Point((closeButton.Left - (mainButtonWidth + 4)) - 4, (_customPanel.ClientRectangle.Height - mainButtonHeight) - 4) }; resetButton.Click += ResetButtonOnClick; _customPanel.Controls.Add(resetButton); // Enable all the toolbar buttons so they're draggable foreach (CRRoundButton button in (from item in collection.Buttons where item.Type == CRToolbarItemType.Button select item.Control).OfType <CRRoundButton>()) { button.Enabled = true; } // Make sure the separators are visible foreach (CRToolbarItem item in collection.Buttons.Where(item => item.Type == CRToolbarItemType.Space || item.Type == CRToolbarItemType.FlexibleSpace)) { item.Control.Visible = true; } // Animate the customise bar into view. The following two lines are to ensure that the // dialog controls are rendered before they appear. _customPanel.Show(); _customPanel.Hide(); Platform.AnimateWindowIn(_customPanel.Handle); _customPanel.Show(this); // Flag we're in customisation mode Customising = true; }