I am writing a text editor. I would like to have a combobox with all the fonts, and I would like the font to change in the rich text box to the one the user selected. How can I code this
Error 10 Operator '&' cannot be applied to operands of type 'System.Drawing.FontStyle' and 'bool' C:\Documents and Settings\HP_Owner\My Documents\mRibbon\Sample\Form1.cs 85 17 Sample
Thats what I get. Something seems to be wrong with this line:
The easiest solution to this is to use the build in FontDialog that comes with VS2005.
Drag a FontDialog from your toolbar (Under the Common Dialogs grouping) onto your form. And add an event handler to a button or menu option on your form that contains the following code...
That code you guys mentioned changes the font. Now, how can I create a combobox, populate it with font sizes and when a user clicks a font size, it changes the font size in the richtextbox
How can I code this?
rubenswise
phb5000
Error 10 Operator '&' cannot be applied to operands of type 'System.Drawing.FontStyle' and 'bool' C:\Documents and Settings\HP_Owner\My Documents\mRibbon\Sample\Form1.cs 85 17 Sample
Thats what I get. Something seems to be wrong with this line:
if
(style & FontStyle.Bold == FontStyle.Bold)Matt
SThorpe
private void BoldButton_Click(object sender, EventArgs e)
{
FontStyle style = this.richTextBox1.Font.Style;
if (style & FontStyle.Bold == FontStyle.Bold)
{
style &= ~FontStyle.Bold;
}
else
{
style |= FontStyle.Bold;
}
this.richTextBox1.Font = new Font(
this.richTextBox1.Font.Name,
this.richTextBox1.Font.Size,
style);
}
changing FontStyle.Bold with the style you want.
pilot2242
Make three buttons and change the following code appropriately for each button
private void BoldButton_Click(object sender, EventArgs e)
{
this.richTextBox1.Font = new Font(this.richTextBox1.Font.Name, this.richTextBox1.Font.Size,FontStyle.Bold);
}
javaGurL
Matt
Drew P
Something like this:
public class MyForm : Form
{
private readonly int[] FontSizes = new int[] { 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24 };
public void SomeFunction()
{
for (int i = 0; i < FontSizes.Length; i++)
{
comboBox2.Items.Add(FontSizes[ i ]);
}
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
this.richTextBox1.Font = new Font(FontFamily.Families[comboBox1.SelectedIndex], FontSize[comboBox2.SelectedIndex]);
}
}
Add more font sizes to the FontSizes array as you like.
Chris
Janus_42
Matt
StephanLotter
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
this.richTextBox1.Font = new Font(FontFamily.Families[this.comboBox1.SelectedIndex],this.richTextBox1.Font.Size);
}
B-me
for (int i = 0; i < FontFamily.Families.Length; i++)
{
this.comboBox1.Items.Add(FontFamily.Families[ i ].Name.ToString());
}
mculo
Matt
gholam ali
Matt
Eindhoven
The easiest solution to this is to use the build in FontDialog that comes with VS2005.
Drag a FontDialog from your toolbar (Under the Common Dialogs grouping) onto your form. And add an event handler to a button or menu option on your form that contains the following code...
if
(fontDialog1.ShowDialog() == DialogResult.OK){
yourRichTextBox.Font = fontPicker.Font;
}
Gene B. 3
Matt
Maxild
Matt