问题
I am trying to load a form class from a program running as a tray icon that originally used
FileList frmFileList = new FileList();
Now instead of a filelist I want to use a custom form but I get the error:
Error 1 'System.Windows.Forms.Control.ControlCollection' does not contain a definition for 'Cast' and no extension method 'Cast' accepting a first argument of type 'System.Windows.Forms.Control.ControlCollection' could be found (are you missing a using directive or an assembly reference?)
Any ideas?
回答1:
It sounds like you forgot using System.Linq;
at the top of your source file. But since you didn't post the sources, I can't say for sure. Posting the line of code that causes the error message, and the using
directives that are in that same file would help.
回答2:
Are you sure you are not trying something like this?
FileList frmFileList = new SomethingDifferent();
If so, change the FileList on the left side to SomethingDifferent.
来源:https://stackoverflow.com/questions/4568815/c-how-to-call-a-form-object-from-a-tray-based-application