error C2665, can't resolve between 2 overloads for System::Windows::Forms::TextRenderer::DrawText

StackOverflow https://stackoverflow.com/questions/7236817

  •  16-01-2021
  •  | 
  •  

Question

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

is giving the error

1>error C2665: 'System::Windows::Forms::TextRenderer::DrawText' : none of the 8 overloads could convert all the argument types

1> could be 'void System::Windows::Forms::TextRenderer::DrawText(System::Drawing::IDeviceContext ^,System::String ^,System::Drawing::Font ^,System::Drawing::Point,System::Drawing::Color)'

1>or 'void System::Windows::Forms::TextRenderer::DrawText(System::Drawing::IDeviceContext ^,System::String ^,System::Drawing::Font ^,System::Drawing::Rectangle,System::Drawing::Color)'

If I lose the line I get no errors. I've tried it the other way with Point and it was working fine in my other project. Any ideas would be appreciated, thanks.

EDIT Here are the pertinent preceeding lines, FWIW..

    System::Drawing::Font sfo(FontFamily::GenericSansSerif, 8.0F, FontStyle::Bold);
Was it helpful?

Solution

You've created your Font object using stack semantics, so in order to pass it to a function wanting a tracking handle (Font^), you need to use unary operator%, much as you would use unary operator& to get an object pointer from an object value in C++:

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

OTHER TIPS

Are you sure the Rectangle class parameter is the good one ?

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

This usually happens when some arguments are implicitly cast but many ways are the target type are found.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top