Click here to Skip to main content
15,893,663 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have two combo_box one of them fill whit font and another one fill whit font size
when i run program say this error:
Value of '0' is not valid for 'emSize'. 'emSize' should be greater than 0 and less than or equal to System.Single.MaxValue.
Parameter name: emSize

font combobox:
C#
private void fontComboBox1_SelectedIndexChanged(object sender, EventArgs e)
       {
           richtextbox1.SelectionFont=newFont(fontComboBox1.Text,Convert.ToInt32(cmbSize.SelectedItem));
       }

font size combobox:
C#
private void cmbSize_SelectedIndexChanged(object sender, EventArgs e)
        {
            richtextbox1.SelectionFont=newFont(fontComboBox1.Text,Convert.ToInt32(cmbSize.SelectedItem));
        }

and error occurred for this line in font combobox:
richtextbox1.SelectionFont=newFont(fontComboBox1.Text,Convert.ToInt32(cmbSize.SelectedItem));
Posted

The error has no relation with combobox.

the error message clearly says the
VB
emSize

that is second param to the font constructor should be from 0 to System.Single.MaxValue

so put a check for
C#
cmbSize.SelectedItem

before line
C#
richtextbox1.SelectionFont=newFont(fontComboBox1.Text,Convert.ToInt32(cmbSize.SelectedItem));.

var FontSize = Convert.ToInt32(cmbSize.SelectedItem);
if (0 < FontSize && FontSize < System.Single.MaxValue )
{
richtextbox1.SelectionFont=newFont(fontComboBox1.Text,Convert.ToInt32(cmbSize.SelectedItem));.


}
else
{
// show error msg for in correct size
}
 
Share this answer
 
v2
Comments
amirmohamad 3-Oct-12 8:33am    
tank's mr.priyank
'emSize' is the font size. The font size 0 is unspecified, and then you'll get an error.
 
Share this answer
 
Comments
amirmohamad 3-Oct-12 8:11am    
have i can set default size to my font size combobox

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900