/// <summary> /// This method allows to set the pen color and push the /// Pen button if requested. /// </summary> /// <param name="colorName">The color</param> /// <param name="push">If true, the Pen button will be pushed and all the /// other buttons in the InkToolBar control will be unpushed.</param> public void SetPen(string colorName, bool push) { //Update pen attributes' color this.m_penAttributes.Color = Color.FromName(colorName); inkOverlay.DefaultDrawingAttributes = m_penAttributes; // Make sure we are not in delete mode inkOverlay.EditingMode = InkOverlayEditingMode.Ink; SetLineIcon(colorName, InkToolBarMode.Pen, widthLinePenIcon); //Set the mode Mode = InkToolBarMode.Pen; // Push only the Pen button if (push) { // Unpush all the buttons foreach (ToolBarButton b in this.Buttons) { b.Pushed = false; } // Push the Pen button this.Buttons[(int)InkToolBarMode.Pen].Pushed = true; } }
/// <summary> /// Switch to eraser mode. /// </summary> public void SwitchToEraserMode() { // Set the mode to Eraser Mode = InkToolBarMode.Eraser; inkOverlay.EraserMode = this.m_eraserAttributes.Mode; inkOverlay.EraserWidth = this.m_eraserAttributes.Size; inkOverlay.EditingMode = InkOverlayEditingMode.Delete; // Push the correct button foreach (ToolBarButton b in this.Buttons) { b.Pushed = false; } this.Buttons[(int)InkToolBarMode.Eraser].Pushed = true; }
/// <summary> /// Set the line below the icon. /// </summary> /// <param name="colorName">The color name.</param> /// <param name="mode">The mode.</param> /// <param name="width">The width of the line.</param> private void SetLineIcon(string colorName, InkToolBarMode mode, int width) { // Update the icon of the highlighter with the selected color Image img = m_imagesAlpha.Images[(int)mode]; Graphics g = Graphics.FromImage(img); // Draw a line underneath of the icon with the selected // color Pen myPen = new Pen(Color.FromName(colorName)); for (int y = lineIconY; y <= lineIconY + width - 1; y++) { g.DrawLine(myPen, lineIconX1, y, lineIconX2, y); } myPen.Dispose(); m_imagesAlpha.Images[(int)mode] = img; this.Invalidate(); }
/// <summary> /// Event handler for the <c>ToolBar.ButtonClick</c> event. /// </summary> /// <param name="sender">Object that invoked the event.</param> /// <param name="e">A <c>ToolBarButtonClickEventArgs</c> that contains the event data.</param> private void ToolBarButtonClicked(Object sender, ToolBarButtonClickEventArgs e) { string colorName = ""; switch (this.Buttons.IndexOf(e.Button)) { case 0: // Push only the button that has been clicked unpushToolBarButtons(); e.Button.Pushed = true; inkOverlay.EditingMode = InkOverlayEditingMode.Ink; colorName = m_penAttributes.Color.Name; SetPen(colorName, true); Mode = InkToolBarMode.Pen; break; case 1: // Push only the button that has been clicked unpushToolBarButtons(); e.Button.Pushed = true; inkOverlay.EditingMode = InkOverlayEditingMode.Ink; colorName = m_highlighterAttributes.Color.Name; SetHighlighter(colorName, true); Mode = InkToolBarMode.Highlighter; break; case 2: // Push only the button that has been clicked unpushToolBarButtons(); e.Button.Pushed = true; Mode = InkToolBarMode.Eraser; inkOverlay.EditingMode = InkOverlayEditingMode.Delete; break; case 3: e.Button.Pushed = false; DeleteAllStrokes(); break; default: break; } }
/// <summary> /// Event handler for the <c>MenuItem.Click</c> event for opening the <c>SettingsDialog</c>. /// </summary> /// <param name="sender">Object that invoked the event.</param> /// <param name="e">An <c>EventArgs</c> that contains the event data.</param> /// <remarks> /// Displays the <c>SettingsDialog</c>, updating any attributes that might have changed for the /// highlighter. /// <para> /// By setting the <c>Mode</c> at the end of the method. The <c>ModeChanged</c> event will be /// fired if needed. /// </para> /// </remarks> private void MenuItemHighlighterSettings_Click(object sender, System.EventArgs e) { // // Display the settings dialog, updating any attributes that might have // changed for the highlighter. // m_settingsDialog = new SettingsDialog(m_highlighterAttributes.Clone()); m_settingsDialog.VisibleChanged += new System.EventHandler(OnSettingsDialogVisibilityChanged); m_settingsDialog.Text = "Highlighter Settings"; if (m_settingsDialog.ShowDialog(this.Parent) == DialogResult.OK) { m_highlighterAttributes = m_settingsDialog.InkDrawingAttributes; UpdateHighlighterMenus(); } // Unsubscribe from the VisibleChanged event. m_settingsDialog.VisibleChanged -= new System.EventHandler(OnSettingsDialogVisibilityChanged); Mode = InkToolBarMode.Highlighter; }
/// <summary> /// Set the highlighter. /// </summary> /// <param name="colorName">The color of the highlighter.</param> /// <param name="push">Whether or not the button should /// be programatically pushed</param> public void SetHighlighter(string colorName, bool push) { //Update highlighter attributes' color this.m_highlighterAttributes.Color = Color.FromName(colorName); inkOverlay.DefaultDrawingAttributes = m_highlighterAttributes; // Make sure we are not in delete mode inkOverlay.EditingMode = InkOverlayEditingMode.Ink; //Set the mode Mode = InkToolBarMode.Highlighter; if (push) { // Unpush all the buttons foreach (ToolBarButton b in this.Buttons) { b.Pushed = false; } this.Buttons[(int)InkToolBarMode.Highlighter].Pushed = true; } SetLineIcon(colorName, InkToolBarMode.Highlighter, widthLineHighlighterIcon); }
/// <summary> /// Set the line below the icon. /// </summary> /// <param name="colorName">The color name.</param> /// <param name="mode">The mode.</param> /// <param name="width">The width of the line.</param> private void SetLineIcon(string colorName, InkToolBarMode mode, int width) { // Update the icon of the highlighter with the selected color Image img = m_imagesAlpha.Images[(int)mode]; Graphics g = Graphics.FromImage(img); // Draw a line underneath of the icon with the selected // color Pen myPen = new Pen(Color.FromName(colorName)); for (int y = lineIconY; y <= lineIconY + width -1; y++) g.DrawLine(myPen, lineIconX1, y, lineIconX2, y); myPen.Dispose(); m_imagesAlpha.Images[(int)mode] = img; this.Invalidate(); }
/// <summary> /// Allow to set the InkOverlay accordingly to the mode (Pen or /// Highlighter) with the color passed in parameter. /// </summary> /// <param name="mode">The mode: InkToolBarMode.Pen or InkToolBarMode.Highlighter</param> /// <param name="color">The pen or highlighter color</param> private void setInkFromMenu(InkToolBarMode mode, Color color) { // Ensure we are in Ink mode inkOverlay.EditingMode = InkOverlayEditingMode.Ink; if (mode == InkToolBarMode.Pen) { // Get the current pen attribute (size of pen / shape) inkOverlay.DefaultDrawingAttributes = inkToolBar.PenAttributes; // Push the button and sync the color in the InkToolBar control // Set the new color inkOverlay.DefaultDrawingAttributes.Color = color; // Update the control attributes and push the pen button inkToolBar.PenAttributes = inkOverlay.DefaultDrawingAttributes; } else if (mode == InkToolBarMode.Highlighter) { // Get the current highlighter attributes (size of highlighter / shape / transparency) inkOverlay.DefaultDrawingAttributes = inkToolBar.HighlighterAttributes; // Push the button and sync the color in the InkToolBar control // Set the new color inkOverlay.DefaultDrawingAttributes.Color = color; // Update the control attributes and push the pen button inkToolBar.HighlighterAttributes = inkOverlay.DefaultDrawingAttributes; } }
/// <summary> /// inkToolBar_ModeChanged event handler. This event is fired /// when the user clicks changed mode: Pen, Highlighter, Eraser. /// </summary> /// <param name="sender">The event sender object</param> /// <param name="e">The event arguments</param> private void inkToolBar_ModeChanged(object sender, System.EventArgs e) { // update the mode mode = inkToolBar.Mode; }
/// <summary> /// Set the highlighter. /// </summary> /// <param name="colorName">The color of the highlighter.</param> /// <param name="push">Whether or not the button should /// be programatically pushed</param> public void SetHighlighter(Color color, bool push) { //Update highlighter attributes' color this.m_highlighterAttributes.Color = color; inkOverlay.DefaultDrawingAttributes = m_highlighterAttributes; // Make sure we are not in delete mode inkOverlay.EditingMode = InkOverlayEditingMode.Ink; //Set the mode Mode = InkToolBarMode.Highlighter; if (push) { // Unpush all the buttons foreach(ToolBarButton b in this.Buttons) { b.Pushed = false; } this.Buttons[(int) InkToolBarMode.Highlighter].Pushed = true; } SetLineIcon(color, InkToolBarMode.Highlighter, widthLineHighlighterIcon); }
/// <summary> /// This method allows to set the pen color and push the /// Pen button if requested. /// </summary> /// <param name="colorName">The color</param> /// <param name="push">If true, the Pen button will be pushed and all the /// other buttons in the InkToolBar control will be unpushed.</param> public void SetPen(Color color, bool push) { //Update pen attributes' color this.m_penAttributes.Color = color; inkOverlay.DefaultDrawingAttributes = m_penAttributes; // Make sure we are not in delete mode inkOverlay.EditingMode = InkOverlayEditingMode.Ink; SetLineIcon(color, InkToolBarMode.Pen, widthLinePenIcon); //Set the mode Mode = InkToolBarMode.Pen; // Push only the Pen button if (push) { // Unpush all the buttons foreach(ToolBarButton b in this.Buttons) { b.Pushed = false; } // Push the Pen button this.Buttons[(int) InkToolBarMode.Pen].Pushed = true; } }
/// <summary> /// Event handler for the <c>ToolBar.ButtonClick</c> event. /// </summary> /// <param name="sender">Object that invoked the event.</param> /// <param name="e">A <c>ToolBarButtonClickEventArgs</c> that contains the event data.</param> private void ToolBarButtonClicked(Object sender, ToolBarButtonClickEventArgs e) { switch (this.Buttons.IndexOf(e.Button)) { case 0: // Push only the button that has been clicked unpushToolBarButtons(); e.Button.Pushed = true; inkOverlay.EditingMode = InkOverlayEditingMode.Ink; SetPen(m_penAttributes.Color, true); Mode = InkToolBarMode.Pen; break; case 1: // Push only the button that has been clicked unpushToolBarButtons(); e.Button.Pushed = true; inkOverlay.EditingMode = InkOverlayEditingMode.Ink; SetHighlighter(m_highlighterAttributes.Color, true); Mode = InkToolBarMode.Highlighter; break; case 2: // Push only the button that has been clicked unpushToolBarButtons(); e.Button.Pushed = true; Mode = InkToolBarMode.Eraser; inkOverlay.EditingMode = InkOverlayEditingMode.Delete; break; case 3: e.Button.Pushed = false; DeleteAllStrokes(); break; default: break; } }
/// <summary> /// Switch to eraser mode. /// </summary> public void SwitchToEraserMode() { // Set the mode to Eraser Mode = InkToolBarMode.Eraser; inkOverlay.EraserMode = this.m_eraserAttributes.Mode; inkOverlay.EraserWidth = this.m_eraserAttributes.Size; inkOverlay.EditingMode = InkOverlayEditingMode.Delete; // Push the correct button foreach(ToolBarButton b in this.Buttons) { b.Pushed = false; } this.Buttons[(int) InkToolBarMode.Eraser].Pushed = true; }
/// <summary> /// Event handler for the <c>MenuItem.Click</c> event for opening the <c>SettingsDialog</c>. /// </summary> /// <param name="sender">Object that invoked the event.</param> /// <param name="e">An <c>EventArgs</c> that contains the event data.</param> /// <remarks> /// Displays the <c>SettingsDialog</c>, updating any attributes that might have changed for the /// highlighter. /// <para> /// By setting the <c>Mode</c> at the end of the method. The <c>ModeChanged</c> event will be /// fired if needed. /// </para> /// </remarks> private void MenuItemHighlighterSettings_Click(object sender, System.EventArgs e) { // // Display the settings dialog, updating any attributes that might have // changed for the highlighter. // m_settingsDialog = new SettingsDialog(m_highlighterAttributes.Clone()); m_settingsDialog.VisibleChanged += new System.EventHandler(OnSettingsDialogVisibilityChanged); m_settingsDialog.Text = Strings.HighlighterSettings; if (m_settingsDialog.ShowDialog(this.Parent) == DialogResult.OK) { m_highlighterAttributes = m_settingsDialog.InkDrawingAttributes; UpdateHighlighterMenus(); } // Unsubscribe from the VisibleChanged event. m_settingsDialog.VisibleChanged -= new System.EventHandler(OnSettingsDialogVisibilityChanged); Mode = InkToolBarMode.Highlighter; }