I’m trying to print a datagridview by drawing to bitmap using visual studio 2008 C++ Windows Forms Application, however I’m having trouble converting the 2 types mentioned in the title. This is the method being called:
private:
void printDocument1_PrintPage(System::Object ^ sender,
System::Drawing::Printing::PrintPageEventArgs ^ e)
{
Bitmap^ bm = gcnew Bitmap(this->dataGridView1->Width, this->dataGridView1->Height);
this->dataGridView1->DrawToBitmap(bm, new Rectangle(0, 0, this->dataGridView1->Width, this->dataGridView1->Height));
e->Graphics->DrawImage(bm, 0, 0);
}
System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
printDialog1->ShowDialog();
printDocument1->Print();
}
However upon compiling the code I’m getting this error:
error C2664: 'System::Windows::Forms::Control::DrawToBitmap' : cannot convert parameter 2 from 'System::Drawing::Rectangle *' to 'System::Drawing::Rectangle'
I’m clueless. How can I fix this error?
Shouldn’t the
new Rectangle(...)code begcnew Rectangle(...)? Remember that in Managed C++,newis NOT the same asgcnew.