-1

如何在许多其他表单上拥有表单控件的属性和功能。对于一种形式,我这样做了:

flashForm flashForm = new flashForm();

对于加载的表单:

        flashForm.SHOW();

并单击按钮:

  flashForm.MOVIE = @"D:\football scoreboard project\football scoreboard\footballscoreb    \quran.swf";
    flashForm.Controls["axShockwaveFlash1"].Show();

但对于其他形式,我不能使用第一行代码,因为它使该形式的新对象不是我想要的形式

4

2 回答 2

1

表单之间有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. 但是,您应该考虑传入触发事件的实际控件(例如按钮)。

于 2013-10-22T17:29:13.953 回答
0

你可能会逃脱singleton

public class MovieForm : Form
{

    private MovieForm _instance;

    private MovieForm()...

    public static MovieForm Instance
    {
        get
        {
            if (_instance == null) _instance = new MovieForm();
            return _instance;
        }
    }

    public void Play()...
    public void Play(Url movieUrl)...
    public void Pause()...
    public void Stop()...
}

用法:

Movieform.Instance.Show();
Movieform.Instance.Play();
于 2013-10-22T18:51:18.643 回答