This code:
private void comboBoxFontSize_SelectedIndexChanged(object sender, EventArgs e) {
rtbResults.Font.Size = Convert.ToInt32(comboBoxFontSize.SelectedItem);
}
…generates this err msg: “Property or indexer ‘System.Drawing.Font.Size’ cannot be assigned to — it is read only”
UPDATE
After attempting the suggested fix, I get this at runtime:
System.FormatException was unhandled
Message=Input string was not in a correct format.
Source=mscorlib
StackTrace:
at System.Number.StringToNumber(String str,
…
Okay, I see: I was using Convert.ToInt32() but the first value in the comboBox was “8.25” -which is, obviously, not an int.
So I tried Convert.ToDouble() and that won’t compile.
Then I see in the intellisense hints that “Calling this method always throws ‘System.InvalidCastException'”*
- as well as Convert.ToSingle()
So must I change my combobox value from 8.25 to 8? 8.25 is the default value…???
UPDATED AGAIN
I read over the weekend (in Petzold’s WP7 book, I think) that 8.25 corresponds to 11. So the 8.25 referred to here is, I think, pixels, which corresponds to font size of 11, which makes a lot more sense now (although still rather overly misleading/confusing).
cause Font is immutable…
Why is Font immutable?
use
or another Font constructor as you need.