出现组合框错误 [英] combobox error occured

查看:85
本文介绍了出现组合框错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有两个combo_box,其中一个填充白色字体,另一个填充白色字体
当我运行程序时说此错误:

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:

"0"的值对于"emSize"无效. "emSize"应大于0且小于或等于System.Single.MaxValue.
参数名称:emSize

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:

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


字体大小组合框:


font size combobox:

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));

推荐答案

该错误与组合框无关.

错误消息清楚地表明
The error has no relation with combobox.

the error message clearly says the
emSize


字体构造函数的第二个参数应该是从0到System.Single.MaxValue

因此请检查


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

so put a check for

cmbSize.SelectedItem


在行之前


before line

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
}


''emSize''是字体大小.未指定字体大小0,然后会出现错误.
''emSize'' is the font size. The font size 0 is unspecified, and then you''ll get an error.


这篇关于出现组合框错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆