错误C3861图形CopyFromScreen:找不到标识符

时间:2015-07-03 07:34:58

标签: visual-studio-2010 visual-c++ c++-cli

我正在使用visual studio 2010,我正在编写一个代码,用于在按钮点击时捕获屏幕。我把代码编写为

 private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
         try
         {
             SaveFileDialog^ save = gcnew SaveFileDialog();
             save->Title = "Save Screenshot";
             save->Filter = "JPEG | *.jpg | Bitmap | *.bmp | Portable Network Graphics|*.png|Graphical Interchange File Format|*.gif";
             save->ShowDialog();
             pictureBox1->Image->Save(save->FileName);
         }
         catch(Exception^ ex)
         {
         MessageBox::Show(ex->Message);

         }


     }
private: System::Void Form1_KeyDown(System::Object^  sender, System::Windows::Forms::KeyEventArgs^  e) {
         if(e->KeyCode == System::Windows::Forms::Keys::Enter)
         {
             Rectangle^ bounds;
             System::Drawing::Bitmap^ screenshot;
             Graphics^ graph;
             bounds = Screen::PrimaryScreen->Bounds;
             screenshot = gcnew System::Drawing::Bitmap(bounds->Width,bounds->Height, System::Drawing::Imaging::PixelFormat::Format32bppArgb);
             graph = Graphics::FromImage(screenshot);
             graph = CopyFromScreen (bounds->X, bounds->Y, 0, 0, bounds-> Size, CopyPixelOperation::SourceCopy);
             pictureBox1->Image = screenshot;

     }
     }

但是这样我得到一个错误,因为CopyFromScreen:找不到标识符。我试图搜索abt这个和它到处显示语法是正确的。

1 个答案:

答案 0 :(得分:0)

假设CopyFromScreen不是您的示例中未包含的自定义free function,则为member of the Graphics class

您应该这样调用它(就像您在上面的行中使用Graphics::FromImage()一样:

graph = Graphics::CopyFromScreen(bounds->X, bounds->Y, 0, 0, bounds-> Size, CopyPixelOperation::SourceCopy);

修改

解决您的意见和我的疏忽: CopyFromScreen不是静态的,因此必须在首先需要创建的特定对象上调用它:

graph.CopyFromScreen(bounds->X, bounds->Y, 0, 0, bounds-> Size, CopyPixelOperation::SourceCopy);