我有一个Windows窗体,在以下布局中显示几个DataGridViews :(
无法访问工作中的图像托管,所以请原谅ASCII艺术......)
???????????????????????????????????????????
???????????????????????????????????????????
?? ?? ??
??????????????? ??
|?????????????? ??
?? ?? ??
??????????????? ??
|?????????????? ??
?? ?? ??
???????????????????????????????????????????
???????????????????????????????????????????
Run Code Online (Sandbox Code Playgroud)
不幸的是,当用户将表单调整为更高时,表单最终看起来像这样:
???????????????????????????????????????????
???????????????????????????????????????????
?? ?? ??
??????????????? ??
| | ||
| | ||
|?????????????? ??
?? ?? ??
??????????????? ??
| | ||
| | ||
|?????????????? ??
?? ?? ??
???????????????????????????????????????????
???????????????????????????????????????????
Run Code Online (Sandbox Code Playgroud)
而不是这个:
???????????????????????????????????????????
???????????????????????????????????????????
?? ?? ??
?? ?? ??
??????????????? ??
|?????????????? ??
?? ?? ??
?? ?? ??
??????????????? ??
|?????????????? …Run Code Online (Sandbox Code Playgroud) 如果是这样,为什么你不能这样做:
public interface IParsable
{
static IParsable Parse(string s);
static bool TryParse(string s, out IParsable);
}
Run Code Online (Sandbox Code Playgroud)
在C#?
编辑:或者,或者:
public interface IParseable<T>
{
static T Parse(string s);
static bool TryParse(string s, out T);
}
Run Code Online (Sandbox Code Playgroud)
编辑#2:我已经通过尝试使用IParsable来了解我的方式的愚蠢,正如下面许多人所建议的那样.我的例子如下.当然,没有办法解决对TryParse的调用......
public IParsable ReadFromKeyboard()
{
IParsable ToReturn;
bool FirstTry = false;
bool Success;
do
{
if (!FirstTry)
DisplayError();
AskForInput();
Success = IParsable.TryParse(Console.ReadLine, out ToReturn);
FirstTry = false;
} while(!Success)
return ToReturn;
}
Run Code Online (Sandbox Code Playgroud)