我正在尝试从以下示例 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 ^)
return null;
->标识符“null”未定义
或者
return nullptr;
-> 不存在从“decltype(nullptr)”到“System::Windows::Forms::Control”的合适的用户定义转换