我对在 Winforms 中使用 C# 中的事件处理程序真的很陌生,目前我遇到以下错误:
错误 1 类型“DotFlickScreenCapture.ScreenCapture”不能用作泛型类型或方法“System.EventHandler”中的类型参数“TEventArgs”。没有从“DotFlickScreenCapture.ScreenCapture”到“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;
}
}
以前有没有人遇到过这个错误?是这样,我该如何克服呢?