0

I'm using visual studio 2010 and i'm writing a code to capture a screen on a button click. i've written the code as

 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;

     }
     }

But with this i'm getting an error as CopyFromScreen:Identifier not found. i tried to search abt this and everywhere it shows syntax is correct.

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
ujwala
  • 1
  • 1

1 Answers1

0

Assuming CopyFromScreen is not a custom free function that isn't included in your example, it is member of the Graphics class.

You should invoke it as such (as you do with Graphics::FromImage() in the line above:

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

EDIT

To address your comment, and my oversight: CopyFromScreen is not static, so it must be invoked on a specific object that you need to create first:

graph.CopyFromScreen(bounds->X, bounds->Y, 0, 0, bounds-> Size, CopyPixelOperation::SourceCopy);
Community
  • 1
  • 1
namezero
  • 2,203
  • 3
  • 24
  • 37
  • when i make the change i'm getting this error C2352: 'System::Drawing::Graphics::CopyFromScreen' : illegal call of non-static member function error C3861: 'CopyFromScreen': identifier not found – ujwala Jul 03 '15 at 08:11
  • i tried to make CopyFromScreen as static i.e static double CopyFromScreen; – ujwala Jul 03 '15 at 08:45
  • I'm not sure I understand what you mean by making `CopyFromScreen` static; it's a library method. Please provide the SSCCE. – namezero Jul 03 '15 at 09:39