我正在努力从下面的例子中翻译以下内容
SplitContainer Splitter Gets Focus Rectangle?
private: Control getFocused(Control::ControlCollection controls)
{
//foreach (Control c in controls)
//{
// if (c.Focused)
// {
// // Return the focused control
// return c;
// }
// else if (c.ContainsFocus)
// {
// // If the focus is contained inside a control's children
// // return the child
// return getFocused(c.Controls);
// }
//}
do
{
if (c.Focused)
{
// Return the focused control
return c;
}
else if (c.ContainsFocus)
{
// If the focus is contained inside a control's children
// return the child
return getFocused(c.Controls);
}
}
while(Control c in controls);
// No control on the form has focus
return null;
}
我正在为DO WHILE循环寻找合适的合成器
while(Control c in controls); // error
并且由于函数'
private: Control getFocused(Control::ControlCollection controls)
'属于Control类型,我需要指定一个返回值,两者都有'
return null;
'和'
return nullptr;
“失败!
编辑:
for(int index = 0; index <= controls.Count; index++)
{
if(controls[index]->Focused)
{
return controls[index];
}
else if (controls[index]->ContainsFocus)
{
return getFocused(controls[index]->Controls);
}
}
return controls[index];
->
不存在从“System::Windows::Forms::Control^”到“System::Windows::Forms::Control”的合适的用户定义转换。
return getFocused(controls[index]->Controls);
->
函数“getFocused”不能用给定的参数列表调用。参数类型为:(System::Windows::Forms::Control::ControlCollection^)
返回null;
->
标识符“null”未定义
或
返回nullptr;
->
不存在从“decltype(nullptr)”到“System::Windows::Forms::Control”的合适的用户定义转换