Reputation: 4121
So, I'm just beginning C# today in hopes of creating a screen shot program. Originally, I was looking into using AIR to accomplish this, as I know a lot more when it comes to web development. None the less, I watched this tutorial (the code I'm trying to use). It shows the very basics of how to get a screen shot.
Therefore, I tried to copy what I saw in the video over to C#, but I get the following error:
'System.Drawing.Graphics.FromImage(System.Drawing.Image)' is a 'method' but is used like a 'type'
Here is my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
namespace ShareFastCommand {
class Program {
static void Main(string[] args) {
int left = 10, top = 10;
int right = 20, bottom = 20;
Bitmap b = new Bitmap(right - left, bottom - top);
Graphics g = new Graphics.FromImage(b);
Rectangle r = new Rectangle(left, top, right - left, bottom - top);
g.CopyFromScreen(left, top, 0, 0, r.Size);
b.Save("C://Users/Josh Foskett/Desktop/test.png", ImageFormat.Png);
}
}
}
I'm using Microsoft Visual C# 2010 Express
.
I've tried Googling the error, among other things, and can't seem to figure it out.
Upvotes: 1
Views: 7485
Reputation: 283684
This is the problem line:
Graphics g = new Graphics.FromImage(b);
What the error message is telling you is that you don't need to say new
there, just
Graphics g = Graphics.FromImage(b);
The FromImage
function already will create a new Graphics
object for you.
Upvotes: 8