I'm trying to get my hands around Forms Painting in Visual C++, so I've created a Form, and on that Form I have added a Panel called cityPanel. I'd like to paint a green rectangle on it. I double clicked cityPanel, which resulted in Visual C++ creating this new function:
private: System::Void cityPanel_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e)
I've filled in the function as so:
private: System::Void cityPanel_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e)
{
Graphics graphicsObj = e->Graphics;
SolidBrush aBrush = gcnew SolidBrush(System::Drawing::Color::Green);
graphicsObj.FillRectangle(aBrush, 100, 100, 200, 300);
}
I get three errors, one on each line, in order:
Error 1 error C3767: 'System::Drawing::Graphics::Graphics': candidate function(s) not accessible
Error 2 error C2664: 'System::Drawing::SolidBrush::SolidBrush(System::Drawing::Color)' : cannot convert parameter 1 from 'System::Drawing::SolidBrush ^' to 'System::Drawing::Color'
Error 3 error C2664: 'void System::Drawing::Graphics::FillRectangle(System::Drawing::Brush ^,float,float,float,float)' : cannot convert parameter 1 from 'System::Drawing::SolidBrush' to 'System::Drawing::Brush ^'
I'm pretty new to the whole concept of "garbage collected" C++ and in particular to the ^
symbol, which I'm kind of using interchangeably with *
in my head. Similarly I'm thinking that gcnew
and new
are the same except that I don't have to delete anything that I create with gcnew when I'm done with it. This is obviously an oversimplification, so in addition to the above code, if anyone has any good links explaining ^
and gcnew
, I'd appreciate them. Thanks!