1

Windows::Forms::TextRenderer::DrawText(gT, numTo100, sfo, Rectangle(2, 2, 12, 12), SystemColors::ControlText);

给出错误

1>error C2665: 'System::Windows::Forms::TextRenderer::DrawText' : 8 个重载都不能转换所有参数类型

1> 可能是 'void System::Windows::Forms::TextRenderer::DrawText(System::Drawing::IDeviceContext ^,System::String ^,System::Drawing::Font ^,System::Drawing::点,系统::绘图::颜色)'

1> 或 'void System::Windows::Forms::TextRenderer::DrawText(System::Drawing::IDeviceContext ^,System::String ^,System::Drawing::Font ^,System::Drawing::Rectangle ,系统::绘图::颜色)'

如果我丢失了这条线,我不会出错。我已经用 Point 尝试了另一种方式,它在我的另一个项目中运行良好。任何想法将不胜感激,谢谢。

编辑 这里是相关的前几行,FWIW ..

    System::Drawing::Font sfo(FontFamily::GenericSansSerif, 8.0F, FontStyle::Bold);
4

2 回答 2

2

您已经Font使用堆栈语义创建了对象,因此为了将其传递给需要跟踪句柄 ( Font^) 的函数,您需要使用 unary operator%,就像operator&在 C++ 中使用 unary 从对象值中获取对象指针一样:

Windows::Forms::TextRenderer::DrawText(
    gT,
    numTo100,
    %sfo,
    Rectangle(2, 2, 12, 12),
    SystemColors::ControlText
);
于 2011-08-29T22:58:32.513 回答
0

你确定 Rectangle 类参数是好参数吗?

Windows::Forms::TextRenderer::DrawText(gT, numTo100, sfo, System::Drawing::Rectangle(2, 2, 12, 12), SystemColors::ControlText); 

这通常发生在某些参数被隐式转换但找到目标类型的许多方法时。

于 2011-08-29T22:56:32.613 回答