Lea*_*ace 10 c# powerpoint windows-forms-designer winforms visual-studio-2012
专家
我想在5分钟后自动洗牌.Windows窗体包含多个查询,多个视频,多个powerpoint.
我有三种窗体形式,如下所示.
表格1代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Daily_System {
  public partial class Form1: Form {
    public Form1() {
      InitializeComponent();
      timer1.Enabled = true;
      timer1.Interval = 5000;
      timer1.Tick += timer1_Tick;
      timer1.Start();
    }
    private void Form1_Load(object sender, EventArgs e) {
      this.WindowState = FormWindowState.Maximized;
      CenterToScreen();
    }
    private Timer timer1 = new Timer();
    private void button1_Click_1(object sender, EventArgs e) {
      this.WindowState = FormWindowState.Minimized;
      Form2 f = new Form2(); // This is bad
      timer2.Enabled = true;
    }
    private void timer2_Tick(object sender, EventArgs e) {
      button1.PerformClick();
    }
  }
}表单2:Microsoft Powerpoint文件
来自网络文件夹的多个powerpoint文件(路径)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using Core = Microsoft.Office.Core;
namespace Daily_System {
  public partial class Form2: Form {
    public Form2() {
      InitializeComponent();
      this.WindowState = FormWindowState.Minimized;
      timer1.Enabled = true;
      timer1.Interval = 15000;
      timer1.Start();
    }
    private void Tick(object sender, EventArgs e) {
      Form3 Next = new Form3();
      Next.Show();
      this.Hide();
      timer1.Stop(); //Stop timer after tick once
    }
    protected override void OnLoad(EventArgs e)
    {
      base.OnLoad(e);
      this.BeginInvoke(new MethodInvoker(delegate() {
        button1.PerformClick();
      }));
    }
    private void button1_Click(object sender, EventArgs e) {
      Microsoft.Office.Interop.PowerPoint.Application pptApp = new Microsoft.Office.Interop.PowerPoint.Application();
      Microsoft.Office.Core.MsoTriState ofalse = Microsoft.Office.Core.MsoTriState.msoFalse;
      Microsoft.Office.Core.MsoTriState otrue = Microsoft.Office.Core.MsoTriState.msoTrue;
      pptApp.Visible = otrue;
      pptApp.Activate();
      Microsoft.Office.Interop.PowerPoint.Presentations ps = pptApp.Presentations;
      var opApp = new Microsoft.Office.Interop.PowerPoint.Application();
      pptApp.SlideShowEnd += PpApp_SlideShowEnd;
      var ppPresentation = ps.Open(@ "C:\Users\ok\Downloads\Parks-WASD2017.pptx", ofalse, ofalse, otrue);
      var settings = ppPresentation.SlideShowSettings;
      settings.Run();
    }
    private void PpApp_SlideShowEnd(Microsoft.Office.Interop.PowerPoint.Presentation Pres) {
      Pres.Saved = Microsoft.Office.Core.MsoTriState.msoTrue;
      Pres.Close();
    }
    private void Form2_Load(object sender, EventArgs e) {
    }
    private void button2_Click(object sender, EventArgs e) {
      this.WindowState = FormWindowState.Minimized;
      Form3 f = new Form3(); // This is bad
      f.Show(); /// f.Show();
      timer1.Enabled = true;
      this.Hide();
      timer1.Stop(); //Stop timer after tick once
    }
    private void timer1_Tick_1(object sender, EventArgs e) {
      button2.PerformClick();
    }
  }
}表格3:多个视频文件(MP4,FLV,MOV等)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Daily_System {
  public partial class Form3: Form {
    public Form3() {
      InitializeComponent();
      timer1.Enabled = true;
      timer1.Interval = 15000;
      timer1.Start();
    }
    private void Form3_Load(object sender, EventArgs e) {
      axWindowsMediaPlayer1.settings.autoStart = true;
    }
    private void axWindowsMediaPlayer1_Enter_1(object sender, EventArgs e) {
      axWindowsMediaPlayer1.URL = @ "C:\Users\ok\Downloads\ok.mp4";
    }
    private void button1_Click(object sender, EventArgs e) {
      this.WindowState = FormWindowState.Minimized;
      Form1 f = new Form1(); // This is bad
      f.Show(); /// f.Show();
      timer1.Enabled = true;
      this.Hide();
      timer1.Stop(); //Stop timer after tick once
    }
    private void timer1_Tick_1(object sender, EventArgs e) {
      button1.PerformClick();
    }
  }
}来自网络文件夹的多个视频文件(路径)
需求:
每个表格应在5分钟后每隔一段时间更换一次.
例如:第一个form1应该显示然后5分钟后form1应该最小化,form2应该显示幻灯片,然后5分钟后form2应该最小化,form3应该播放视频然后5分钟后form3应该最小化并暂停视频然后form1应该显示.
它应该继续执行与上面相同的步骤.
最终条件:所有表格应在下午6点(每天)准确停止,并应在早上7点(每天)自动开始.
请指教...
OnStart()一种方法是为表单创建基类来控制它们的最小化和最大化,并通过覆盖和方法找出特定表单何时最小化或最大化OnStop()。这可以按如下方式完成:
定义名为 的新基类CustomForm:
public class CustomForm : Form
{
    public static List<CustomForm> AllForms = new List<CustomForm>();
    private static int CurrentFormIndex = 0;
    private static Timer SliderTimer = new Timer() { Interval = 5000 }; // { Interval = 5 * 60000 };
    public static void Start(params CustomForm[] forms)
    {
        AllForms.AddRange(forms);
        forms[0].Show();
        forms[0].WindowState = FormWindowState.Maximized;
        AllForms[0].OnStart(AllForms[0]);
        SliderTimer.Tick += SliderTimer_Tick;
        SliderTimer.Start();
    }
    private static void SliderTimer_Tick(object sender, EventArgs e)
    {
        SliderTimer.Stop();
        // Minimizing current form
        AllForms[CurrentFormIndex].OnStop(AllForms[CurrentFormIndex]);
        AllForms[CurrentFormIndex].WindowState = FormWindowState.Minimized;
        // Maximizing next form
        int NextFormIndex = (CurrentFormIndex + 1) % AllForms.Count;
        if (!AllForms[NextFormIndex].Visible)
            AllForms[NextFormIndex].Show();
        AllForms[NextFormIndex].WindowState = FormWindowState.Maximized;
        AllForms[NextFormIndex].OnStart(AllForms[NextFormIndex]);
        CurrentFormIndex = NextFormIndex;
        SliderTimer.Start();
    }
    // Application will exits when one of forms being closed
    protected override void OnFormClosed(FormClosedEventArgs e)
    {
        base.OnFormClosed(e);
        Application.Exit();
    }
    // For overriding in forms to Start something such as playing or etc
    protected virtual void OnStart(CustomForm Sender)
    {
    }
    // For overriding in forms to Stop something such as playing or etc
    protected virtual void OnStop(CustomForm Sender)
    {
    }
}
更改Program类如下:
static class Program
{
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        CustomForm.Start(new Form1(), new Form2(), new Form3());
        Application.Run();
    }
}
将您的表单更改为继承,CustomForm而不是Form如下所示:
public partial class Form1 : CustomForm
{
    public Form1()
    {
        InitializeComponent();
    }
    private void Form1_Shown(object sender, EventArgs e)
    {
        // axWindowsMediaPlayer1.URL = @"C:\Users\ok\Downloads\ok.mp4";
        WMPLib.IWMPMedia v1 = axWindowsMediaPlayer1.newMedia(@"d:\1.mp4");
        axWindowsMediaPlayer1.currentPlaylist.appendItem(v1);
        WMPLib.IWMPMedia v2 = axWindowsMediaPlayer1.newMedia(@"d:\2.mp4");
        axWindowsMediaPlayer1.currentPlaylist.appendItem(v2);
        WMPLib.IWMPMedia v3 = axWindowsMediaPlayer1.newMedia(@"d:\3.mp4");
        axWindowsMediaPlayer1.currentPlaylist.appendItem(v3);
    }
    // To start playing video and etc when form being maximized
    protected override void OnStart(CustomForm Sender)
    {
        axWindowsMediaPlayer1.Ctlcontrols.play();
    }
    // To stop playing video and etc when form being minimized
    protected override void OnStop(CustomForm Sender)
    {
        axWindowsMediaPlayer1.Ctlcontrols.pause();
    }
}
表格2:
public partial class Form2 : CustomForm
{
    Microsoft.Office.Interop.PowerPoint.Presentation ppPresentation;
    Microsoft.Office.Interop.PowerPoint.SlideShowSettings settings;
    Microsoft.Office.Interop.PowerPoint.Application opApp;
    int StartingSlide = 1;
    public Form2()
    {
        InitializeComponent();
    }
    protected override void OnStart(CustomForm Sender)
    {
        Microsoft.Office.Interop.PowerPoint.Application pptApp = new Microsoft.Office.Interop.PowerPoint.Application();
        Microsoft.Office.Core.MsoTriState ofalse = Microsoft.Office.Core.MsoTriState.msoFalse;
        Microsoft.Office.Core.MsoTriState otrue = Microsoft.Office.Core.MsoTriState.msoTrue;
        pptApp.Visible = otrue;
        pptApp.Activate();
        Microsoft.Office.Interop.PowerPoint.Presentations ps = pptApp.Presentations;
        opApp = new Microsoft.Office.Interop.PowerPoint.Application();
        opApp.SlideShowNextSlide += OpApp_SlideShowNextSlide;
        ppPresentation = ps.Open(@"c:\a.pptx", ofalse, ofalse, otrue);
        settings = ppPresentation.SlideShowSettings;
        settings.RangeType = Microsoft.Office.Interop.PowerPoint.PpSlideShowRangeType.ppShowSlideRange;
        settings.StartingSlide = StartingSlide;
        settings.Run();
    }
    private void OpApp_SlideShowNextSlide(Microsoft.Office.Interop.PowerPoint.SlideShowWindow Wn)
    {
        StartingSlide = Wn.View.CurrentShowPosition;
    }
    protected override void OnStop(CustomForm Sender)
    {
        ppPresentation.Close();
        //opApp.Quit();
        Process.Start("cmd", "/c taskkill /im POWERPNT.EXE");
    }
}
| 归档时间: | 
 | 
| 查看次数: | 303 次 | 
| 最近记录: |