/// <summary> /// Combined event handler for handling all the buttons on tool strip. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void format_Text_Click(object sender, EventArgs e) { try { ToolStripButton pressed_Btn = (ToolStripButton)sender; //For BOLD, ITALIC, UNDERLINE, STRIKE THROUGH. if (pressed_Btn == tsb_Bold || pressed_Btn == tsb_Italic || pressed_Btn == tsb_UnderLine || pressed_Btn == tsb_StrikeThrough) { if (this.ActiveMdiChild != null) { Text_Viewer textView = (Text_Viewer)this.ActiveMdiChild; Font temp_Font = textView.selected_Font_Settings; if (pressed_Btn == tsb_Bold) { if (temp_Font.Bold) { FontStyle style = FontStyle.Regular; if (temp_Font.Italic) { style = style | FontStyle.Italic; } if (temp_Font.Underline) { style = style | FontStyle.Underline; } if (temp_Font.Strikeout) { style = style | FontStyle.Strikeout; } textView.format_Font(new Font(temp_Font.FontFamily, temp_Font.Size, style), textView.selected_BackColor, textView.selected_ForeColor); } else { textView.format_Font(new Font(temp_Font.FontFamily, temp_Font.Size, temp_Font.Style | FontStyle.Bold), textView.selected_BackColor, textView.selected_ForeColor); } } if (pressed_Btn == tsb_Italic) { if (temp_Font.Italic) { FontStyle style = FontStyle.Regular; if (temp_Font.Bold) { style = style | FontStyle.Bold; } if (temp_Font.Underline) { style = style | FontStyle.Underline; } if (temp_Font.Strikeout) { style = style | FontStyle.Strikeout; } textView.format_Font(new Font(temp_Font.FontFamily, temp_Font.Size, style), textView.selected_BackColor, textView.selected_ForeColor); } else { textView.format_Font(new Font(temp_Font.FontFamily, temp_Font.Size, temp_Font.Style | FontStyle.Italic), textView.selected_BackColor, textView.selected_ForeColor); } } if (pressed_Btn == tsb_UnderLine) { if (temp_Font.Underline) { FontStyle style = FontStyle.Regular; if (temp_Font.Bold) { style = style | FontStyle.Bold; } if (temp_Font.Italic) { style = style | FontStyle.Italic; } if (temp_Font.Strikeout) { style = style | FontStyle.Strikeout; } textView.format_Font(new Font(temp_Font.FontFamily, temp_Font.Size, style), textView.selected_BackColor, textView.selected_ForeColor); } else { textView.format_Font(new Font(temp_Font.FontFamily, temp_Font.Size, temp_Font.Style | FontStyle.Underline), textView.selected_BackColor, textView.selected_ForeColor); } } if (pressed_Btn == tsb_StrikeThrough) { if (temp_Font.Strikeout) { FontStyle style = FontStyle.Regular; if (temp_Font.Bold) { style = style | FontStyle.Bold; } if (temp_Font.Underline) { style = style | FontStyle.Underline; } if (temp_Font.Italic) { style = style | FontStyle.Italic; } textView.format_Font(new Font(temp_Font.FontFamily, temp_Font.Size, style), textView.selected_BackColor, textView.selected_ForeColor); } else { textView.format_Font(new Font(temp_Font.FontFamily, temp_Font.Size, temp_Font.Style | FontStyle.Strikeout), textView.selected_BackColor, textView.selected_ForeColor); } } } } else if (pressed_Btn == tsb_AlignLeft || pressed_Btn == tsb_AlignCenter || pressed_Btn == tsb_AlignRight) {//For ALIGN LEFT, ALIGN CENTER, ALIGN RIGHT. if (this.ActiveMdiChild != null) { Text_Viewer text_view = (Text_Viewer)this.ActiveMdiChild; text_view.format_Paragraph(pressed_Btn.Text, text_view.selected_Bullets); } } else if (pressed_Btn == tsb_IncreaseIndent || pressed_Btn == tsb_DecreaseIndent) {//For INCREASE DECREASE INDENT. if (this.ActiveMdiChild != null) { Text_Viewer text_view = (Text_Viewer)this.ActiveMdiChild; if (pressed_Btn == tsb_IncreaseIndent) { text_view.increase_decrease_Indent(true); } else { text_view.increase_decrease_Indent(false); } } } else if (pressed_Btn == tsb_Bullet) {//For ENABLING/DISABLING BULLETS. if (this.ActiveMdiChild != null) { Text_Viewer text_view = (Text_Viewer)this.ActiveMdiChild; if (text_view.selected_Bullets) { text_view.format_Paragraph(text_view.selected_Alignment.ToString(), false); } else { text_view.format_Paragraph(text_view.selected_Alignment.ToString(), true); } } } } catch (Exception) { MessageBox.Show("Error: Cannot Handle Multiple Fonts and Size"); } }
/// <summary> /// Setting the Button Color and the alignment state according to formatting applied /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Set_Button_State(object sender, EventArgs e) { Button pressed_Btn = (Button)sender; if (pressed_Btn.Text != "I" && pressed_Btn.Text != "D") { if (pressed_Btn.Text != "Bullet") { if (pressed_Btn.Text == "Left") { this.curr_Para_Aligment = "Left"; btn_Left.BackColor = Color.Black; btn_Left.ForeColor = Color.White; btn_Right.BackColor = Color.LightGray; btn_Right.ForeColor = Color.Black; btn_Center.BackColor = Color.LightGray; btn_Center.ForeColor = Color.Black; } else if (pressed_Btn.Text == "Right") { this.curr_Para_Aligment = "Right"; btn_Left.BackColor = Color.LightGray; btn_Left.ForeColor = Color.Black; btn_Right.BackColor = Color.Black; btn_Right.ForeColor = Color.White; btn_Center.BackColor = Color.LightGray; btn_Center.ForeColor = Color.Black; } else if (pressed_Btn.Text == "Center") { this.curr_Para_Aligment = "Center"; btn_Left.BackColor = Color.LightGray; btn_Left.ForeColor = Color.Black; btn_Right.BackColor = Color.LightGray; btn_Right.ForeColor = Color.Black; btn_Center.BackColor = Color.Black; btn_Center.ForeColor = Color.White; } } else { if (this.is_Bullets_Applied) { btn_Bullet.BackColor = Color.LightGray; btn_Bullet.ForeColor = Color.Black; this.is_Bullets_Applied = false; } else { this.is_Bullets_Applied = true; btn_Bullet.BackColor = Color.Black; btn_Bullet.ForeColor = Color.White; } } } else { if (pressed_Btn.Text == "Increase") { text_View.increase_decrease_Indent(true); } else if (pressed_Btn.Text == "Decrease") { text_View.increase_decrease_Indent(false); } } }