drawToBitmap将System :: Windows :: Forms :: Control :: DrawToBitmap转换为System :: Drawing :: Rectangle的方法

时间:2012-01-06 19:20:39

标签: c++ visual-studio methods

我正在尝试通过使用visual studio 2008 C ++ Windows窗体应用程序绘制到位图来打印数据网格视图,但是我无法转换标题中提到的两种类型。这是被称为的方法:

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();
    }

但是在编译代码时我收到了这个错误:

error C2664: 'System::Windows::Forms::Control::DrawToBitmap' : cannot convert parameter 2 from 'System::Drawing::Rectangle *' to 'System::Drawing::Rectangle'

我很无能为力。我该如何解决这个错误?

1 个答案:

答案 0 :(得分:2)

new Rectangle(...)代码不应该是gcnew Rectangle(...)吗?请记住,在托管C ++中,newgcnew不同。

相关问题