Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 更改高度时控件不可见_C#_Windows Applications - Fatal编程技术网

C# 更改高度时控件不可见

C# 更改高度时控件不可见,c#,windows-applications,C#,Windows Applications,上面这行代码是在windows窗体缩小到很小并且控件不可见时执行的,相反,它导致我的窗体关闭。考虑到float.Parse(txtHeigth.Text)),很可能存在解析异常 第一:使用TryParse(..) 第二:始终指定文化 所以使用方法(示例) 第三:至少从提供的代码来看,没有先将文本转换为float,然后再转换为int。立即将其转换为所需的目标格式,因此int放置一个try-and-catch块,有什么例外?您的问题没有解释为什么表单会关闭,但是,我无法理解将float转换为int在

上面这行代码是在windows窗体缩小到很小并且控件不可见时执行的,相反,它导致我的窗体关闭。

考虑到
float.Parse(txtHeigth.Text))
,很可能存在解析异常

第一:使用
TryParse(..)

第二:始终指定文化

所以使用方法(示例)


第三:至少从提供的代码来看,没有先将文本转换为
float
,然后再转换为
int
。立即将其转换为所需的目标格式,因此
int

放置一个try-and-catch块,有什么例外?您的问题没有解释为什么表单会关闭,但是,我无法理解将float转换为int在表单中设置一个最小高度,或者将上面的行包装在一个if块中,以确保它不会将表单收缩到无法使用的高度。我在理解这个问题时遇到困难。@santhosh kumar vadlamani,我是krishna kishore。。。你有办法解决这个问题吗?
int Height=Convert.ToInt32(float.Parse(txtHeight.Text)) 
var result = 0; 

if(float.TryParse(txtHeight.Text, 
              NumberStyles.Any, CultureInfo.InvariantCulture, out result)) {
   //Conversion succeed 
}