Text Size

How would you set the size of the text?

becuase I have this:

RtextboxUC thisrichtextbox = GetCurrentTextBox();

thisrichtextbox.TextBox.Font.SizeInPoints =newFont(thisrichtextbox.Font, TextSizeCombo.SelectedItem);

but I get 2 erros with the thisrichtextbox.TextBox.Font.SizeInPoints =newFont(thisrichtextbox.Font, TextSizeCombo.SelectedItem);

1:The best overloaded method match for 'System.Drawing.Font.Font(System.Drawing.Font, System.Drawing.FontStyle)' has some invalid arguments2:cannot convert from 'object' to 'System.Drawing.FontStyle'

Thanks :)

[1042 byte] By [programmer01] at [2007-12-25]
# 1

thisrichtextbox.TextBox.Font.SizeInPoints = new Font(thisrichtextbox.Font, Convert.ToSingle(TextSizeCombo.SelectedItem));

DMan1 at 2007-9-3 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 2

I got errors on:

new Font(thisrichtextbox.Font, Convert.ToSingle(TextSizeCombo.SelectedItem));

they are:

Error 1 The best overloaded method match for 'System.Drawing.Font.Font(System.Drawing.Font, System.Drawing.FontStyle)' has some invalid arguments
Error 2 Argument '2': cannot convert from 'float' to 'System.Drawing.FontStyle'

Thanks :)

programmer01 at 2007-9-3 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 3

Hi,

From the error message 2, its saying that you are passing invalid argument for System.Drawing.FontStyle. Did you try passing the fontstyle, something like this...?

new System.Drawing.Font("Tahoma",System.Drawing.FontStyle.Regular)

Thank you,
Bhanu.

BhanuPrakashNunna-MSFT at 2007-9-3 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 4

Like this:

thisrichtextbox.TextBox.Font.SizeInPoints = new Font(thisrichtextbox.Font, Convert.ToSingle(toolStripComboBox1.SelectedItem), FontStyle.Regular);

?

If so then I got 2 errors:

Error 1 The best overloaded method match for 'System.Drawing.Font.Font(System.Drawing.FontFamily, float, System.Drawing.FontStyle)' has some invalid arguments
Error 2 Argument '1': cannot convert from 'System.Drawing.Font' to 'System.Drawing.FontFamily'

If not...then could you explain again?

Thanks :)

programmer01 at 2007-9-3 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 5

Ok, I found abetter way, here is what I did:

System.Drawing.Font thecurrentFont = thisrichtextbox.TextBox.SelectionFont;

thisrichtextbox.TextBox.SelectionFont = new Font(thecurrentFont.FontFamily, comboBox1.SelectedIndex, thecurrentFont.Style);

But now what happens is there are 0 errors BUT if Ic hange the size int eh combobox to 18 then the size becomes even lower then 8... If I put it on 8 then I get a runtime error aboutt he size being smaller then I can be.... Is there somthing that I should change in the code or in the combobox items?

Thanks for your help :)

programmer01 at 2007-9-3 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 6
Your

problem is related to the use of comboBox1.SelectedIndex. It returns

the index for the selected item; if you select the first item in the

combobox dropdown list, SelectedIndex will be 0. You'll create a font

that's 0 points high. You want to use the value selected by

SelectedIndex. Assuming you just list the point values in the

combobox, use something like this:

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) {

float points = Convert.ToSingle(comboBox1.Items[comboBox1.SelectedIndex]);

comboBox1.Font = new Font(comboBox1.Font.FontFamily, points, comboBox1.Font.Style);

}

nobugz at 2007-9-3 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 7

Ok, I got no errors with it, so when I tested it I set it to 50 and......the size stayed 8 but the combobox item text size became 50....

Actualy I jsut looked over it and found the problem, You were setting it to change the combobox size....

So I changed it to set the richtextbox font size, so now it works just fine other then the point it changes ALL the text to that size...How would I amke it just do the selected text?

Thanks :)

programmer01 at 2007-9-3 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 8
Glad you figured it out. To change the font size of the selection, assign the SelectionFont property:

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) {

if (richTextBox1.SelectionLength == 0)

MessageBox.Show("Please select something first");

else {

float points = Convert.ToSingle(comboBox1.Items[comboBox1.SelectedIndex]);

richTextBox1.SelectionFont =

new Font(richTextBox1.Font.FontFamily, points, richTextBox1.Font.Style);

}

}

nobugz at 2007-9-3 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 9

Ok,

thanks it worked :)

programmer01 at 2007-9-3 > top of Msdn Tech,Windows Forms,Windows Forms General...