FormatException未处理

FormatException未处理

本文介绍了System.FormatException未处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更改RichTextBox字体,样式,大小如下。但是在运行时间期间发生异常,如果是条件,则在最后一个错误是输入字符串格式不正确。



I'm trying change RichTextBox font, style, size as below. But exception occurred during at run time in last else if condition. An error is "Input string was not in a correct format."

public void FontFormation()
        {
            if (FontStyle.Bold.ToString() == ddlFontStyle.Text.ToString())
            {
                rchtxtMainBody.Font = new System.Drawing.Font(ddlFont.Text.ToString().Trim(), Convert.ToUInt32(ddlFontSize.Text), FontStyle.Bold);
            }
            else if(FontStyle.Italic.ToString() == ddlFontStyle.Text.ToString())
            {
                rchtxtMainBody.Font = new System.Drawing.Font(ddlFont.Text.ToString().Trim(), Convert.ToUInt32(ddlFontSize.Text), FontStyle.Italic);
            }
            else if(FontStyle.Regular.ToString() == ddlFontStyle.Text.ToString())
            {
                rchtxtMainBody.Font = new System.Drawing.Font(ddlFont.Text.ToString().Trim(), Convert.ToUInt32(ddlFontSize.Text), FontStyle.Regular);
            }
        }





在我的代码中,前两个条件正在执行而没有错误,但最后一个条件单独显示上述错误。如果我删除我的最后一个if条件,即FontStyle.Regular.ToString()== ddlFontStyle.Text。代码执行没有任何错误。



Plz告诉我如何解决这个问题。



In my code first two conditions are executing without error but last one alone showing aforesaid error. If i remove my last else if condition i.e FontStyle.Regular.ToString()== ddlFontStyle.Text. code is getting executed without any error.

Plz tell me how to fix this.

推荐答案


这篇关于System.FormatException未处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 11:52