Working with RichText Box Control to set Bold, Underline, and Italics


if (e.KeyCode == Keys.F5)
{
    Editor.Load();
}
else if (e.KeyCode == Keys.B && e.Modifiers == Keys.Control)
{
this.BoldtoolStripButton_Click(this, e);
}
else if (e.KeyCode == Keys.I && e.Modifiers == Keys.Control)
{
this.ItalicstoolStripButton_Click(this, e);

}
else if (e.KeyCode == Keys.U && e.Modifiers == Keys.Control)
{
this.UnderLinetoolStripButton_Click(this, e);
}
else if (e.KeyCode == Keys.OemCloseBrackets && e.Modifiers == Keys.Control)
{
System.Drawing.
Font currentFont = this.rtbDocument.SelectionFont;
if (this.rtbDocument.SelectionFont != null)
{
this.rtbDocument.SelectionFont = new System.Drawing.Font(currentFont.FontFamily.ToString(), currentFont.Size + 1);
}
else
{
this.rtbDocument.Font = new System.Drawing.Font(currentFont.FontFamily.ToString(), currentFont.Size + 1);

}
}
else if (e.KeyCode == Keys.OemOpenBrackets && e.Modifiers == Keys.Control)
{
System.Drawing.
Font currentFont = this.rtbDocument.SelectionFont;
if (this.rtbDocument.SelectionFont != null)
this.rtbDocument.SelectionFont = new System.Drawing.Font(currentFont.FontFamily.ToString(), currentFont.Size - 1);
else
this.rtbDocument.Font = new System.Drawing.Font(currentFont.FontFamily.ToString(), currentFont.Size - 1);
}
}










Worker is generic for Any Form.


public
void SetBold()
{
if (Worker.rtbDocument.SelectionFont != null)
{
System.Drawing.
Font currentFont = Worker.rtbDocument.SelectionFont;
System.Drawing.
FontStyle newFontStyle;
if (Worker.rtbDocument.SelectionFont.Bold == true)
newFontStyle =
FontStyle.Regular;
else
newFontStyle =
FontStyle.Bold;
Worker.rtbDocument.SelectionFont =
new Font(
currentFont.FontFamily,
currentFont.Size,
newFontStyle
);
}

}
public void SetItalics()
{
if (Worker.rtbDocument.SelectionFont != null)
{
System.Drawing.
Font currentFont = Worker.rtbDocument.SelectionFont;
System.Drawing.
FontStyle newFontStyle;
if (Worker.rtbDocument.SelectionFont.Italic == true)
newFontStyle =
FontStyle.Regular;
else
newFontStyle =
FontStyle.Italic;
Worker.rtbDocument.SelectionFont =
new Font(
currentFont.FontFamily,
currentFont.Size,
newFontStyle
);
}
}
public void SetUnderLine()
{
if (Worker.rtbDocument.SelectionFont != null)
{
System.Drawing.
Font currentFont = Worker.rtbDocument.SelectionFont;
System.Drawing.
FontStyle newFontStyle;
if (Worker.rtbDocument.SelectionFont.Underline == true)
newFontStyle =
FontStyle.Regular;
else
newFontStyle =
FontStyle.Underline;
Worker.rtbDocument.SelectionFont =
new Font(
currentFont.FontFamily,
currentFont.Size,
newFontStyle
);
}
}
Ebook Download
View all
Learn
View all