表单之间有tons
多种通信方式。我想您的情况是您可以控制以某种形式加载和播放电影。我想介绍这种机制,其中控件不需要知道显示,它只是触发一些事件来通知I want to display this movie
,显示表单也不需要在任何类中保存/引用,它只需要订阅事件并在事件触发时显示/更改电影。看起来我们需要一些静态事件。您可以在主 UI 类中定义此静态事件,如下所示:
public partial class MainUI : Form {
//...
public class RequireShowMovieEventArgs : EventArgs {
public string MoviePath {get; private set;}
public RequireShowMovieEventArgs(string moviePath){
MoviePath = moviePath;
}
}
public delegate void RequireShowMovieEventHandler(object sender, RequireShowMovieEventArgs e);
public static event RequireShowMovieEventHandler RequireShowMovie;
//...
}
//just fire the event when you want to show/change the movie
RequireShowMovieEventHandler handler = MainUI.RequireShowMovie;
if(handler != null) handler(yourObject, new MainUI.RequireShowMovieEventArgs(@"D:\football scoreboard project\football scoreboard\footballscoreb \quran.swf"));
//Your display form (which you call flashForm)
public class FlashForm : Form {
public FlashForm(){
MainUI.RequireShowMovie += RequiresShowMovieHandler;
Disposed += (s,e) => {
MainUI.RequireShowMovie -= RequiresShowMovieHandler;
};
}
private void RequireShowMovieHandler(object sender, MainUI.RequireShowMovieEventArgs e){
MOVIE = e.MoviePath;
axShockwaveFlash1.Show();
}
//....
}
注意:yourObject
我上面的代码中的任何你想要的,甚至null
. 但是,您应该考虑传入触发事件的实际控件(例如按钮)。