So i was wondering if there is any better way of doing it?
The code im using at the moment is below:
private void fontCombo1_SelectedIndexChanged(object sender, EventArgs e)
{
Font Current = richTextBox1.SelectionFont; // Record current Font
richTextBox1.SuspendLayout();
Font lastFont = null;
int selStart = richTextBox1.Selectionstart;
int selEnd = richTextBox1.Selectionstart + richTextBox1.SelectionLength;
int currentStart = selStart;
for (int i = selStart; i < selEnd; i++)
{
richTextBox1.Select(i, 1); // Select each character of the selected string
lastFont = richTextBox1.SelectionFont; // record the font properties of each character
if (fontCombo1.Text == "Monotype Corsiva" || fontCombo1.Text.ToString() == "Vivaldi")
{
Font newFont = new Font(this.fontCombo1.Text, lastFont.Size, FontStyle.Italic);
richTextBox1.SelectionFont = newFont;
}
else
{
Font newFont = new Font(this.fontCombo1.Text, lastFont.Size, lastFont.Style);
richTextBox1.SelectionFont = newFont;
}
}
if (richTextBox1.SelectedText == "") // Check to see if were changing selected Fonts
{
if (fontCombo1.Text == "Monotype Corsiva" || fontCombo1.Text.ToString() == "Vivaldi")
{
Font newFont = new Font(this.fontCombo1.Text, Current.Size, FontStyle.Italic);
richTextBox1.SelectionFont = newFont;
}
else
richTextBox1.SelectionFont = new Font(this.fontCombo1.Text, Current.Size, Current.Style);
}
richTextBox1.ResumeLayout();
// Show changes
richTextBox1.Invalidate();
richTextBox1.Focus();
}
Any Help appreciated!!
Thanks

New Topic/Question
Reply




MultiQuote




|