我真的很新的WinForms和此刻的我有以下的错误使用的事件处理程序在C#:事件处理程序
Error 1 The type 'DotFlickScreenCapture.ScreenCapture' cannot be used as type parameter 'TEventArgs' in the generic type or method 'System.EventHandler'. There is no implicit reference conversion from 'DotFlickScreenCapture.ScreenCapture' to 'System.EventArgs'.
我试图寻找一种方法来打败这个错误,但到目前为止,我的谷歌搜索没有发现任何东西。
线这个错误点是这个:
public EventHandler<ScreenCapture> capture;
,从我可以告诉,这个类:
public class ScreenCapture
{
public delegate void StatusUpdateHandler(object sender, ProgressEventArgs e);
public event StatusUpdateHandler OnUpdateStatus;
public bool saveToClipboard = true;
public void CaptureImage(bool showCursor, Size curSize, Point curPos, Point SourcePoint, Point DestinationPoint, Rectangle SelectionRectangle, string FilePath, string extension)
{
Bitmap bitmap = new Bitmap(SelectionRectangle.Width, SelectionRectangle.Height);
using (Graphics g = Graphics.FromImage(bitmap))
{
g.CopyFromScreen(SourcePoint, DestinationPoint, SelectionRectangle.Size);
if (showCursor)
{
Rectangle cursorBounds = new Rectangle(curPos, curSize);
Cursors.Default.Draw(g, cursorBounds);
}
}
if (saveToClipboard)
{
Image img = (Image)bitmap;
Clipboard.SetImage(img);
if (OnUpdateStatus == null) return;
ProgressEventArgs args = new ProgressEventArgs(img);
OnUpdateStatus(this, args);
}
else
{
switch (extension)
{
case ".bmp":
bitmap.Save(FilePath, ImageFormat.Bmp);
break;
case ".jpg":
bitmap.Save(FilePath, ImageFormat.Jpeg);
break;
case ".gif":
bitmap.Save(FilePath, ImageFormat.Gif);
break;
case ".tiff":
bitmap.Save(FilePath, ImageFormat.Tiff);
break;
case ".png":
bitmap.Save(FilePath, ImageFormat.Png);
break;
default:
bitmap.Save(FilePath, ImageFormat.Jpeg);
break;
}
}
}
}
public class ProgressEventArgs : EventArgs
{
public Image CapturedImage { get; private set; }
public ProgressEventArgs(Image img)
{
CapturedImage = img;
}
}
有没有人经历过这个错误?是的,我如何克服它?
看来这不是在4.5 –
需要什么我只是发现了。试着在4.0的4.5.2项目中编译并得到错误。 4.0需要明确地说它是一个'EventArgs'而4.5 +你不需要。我简单地假设你传递的是一个'EventArgs' – Franck