定制Powerpoint幻灯片

发布于 2024-11-07 10:37:36 字数 363 浏览 0 评论 0原文

我只使用 C# 几个星期,但我却陷入了线程问题。

我一直在构建一个自定义幻灯片,它实现了托管在由独立类处理的 winform 中的 .ppt 演示文稿。幻灯片放映结束后,另一个程序显示车间的动态数据。需要向第二个程序发送命令以进入全屏模式,因为我无权访问它的源代码。

使用 Setforegroundwindow API,我可以轻松地在两个应用程序之间切换,并使用 COM 接口控制电源点,但随着屏幕大小的调整,过渡会变得不稳定。我想覆盖一个空白的黑色 winform,在发生这种转换时淡入淡出。到目前为止,我还没有成功地做到这一点,我已经尝试在单独的线程上运行淡入淡出形式和过渡,但我还没有完全弄清楚。如果有人对如何做到这一点有任何建议,我们将不胜感激。

谢谢。

I have only been working with C# for a few weeks and I have gotten stuck on a threading issue.

I've been building a custom slideshow that implements a .ppt presentation hosted in a winform handled by an independent class. The slideshow switches off with another program that displays dynamic data from a shop floor. This second program needs to be sent a command to enter full screen mode as I do not have access to it's source code.

Using Setforegroundwindow API I can easily switch between the two applications and control the power point with the COM interface but the transition is choppy with screens resizing. I would like to overlay a blank black winform that fades in and out while this transition occurs. So far I have been unsuccessful in doing this smoothly, I have tried running the fading form and transition on separate threads but I haven't got it quite figured out. If anyone might have any advice on how to do this it would be much appreciated.

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

暖风昔人 2024-11-14 10:37:36

一种想法...

有两个 ppt 加载器。

当前的和您正在加载的新的。

保持当前的可见和活动状态,直到新的准备就绪。然后,一旦新的准备好,就隐藏当前的。这应该会给你一个很好的过渡。

由于将有两个观看者处于活动状态,因此资源消耗会更大一些,但切换应该会更流畅。

可能想要区分加载和启动。这样您就可以在后台加载,加载后,显示并启动 ppt。

One thought...

Have two ppt loaders.

The current one and the new one you are loading.

Keep the current visible and active until the new one is ready. Then once the new one is ready hide the current one. That should give you a nice transition.

Since there will be two viewers active, it will be a little more resource intensive, but switching should be smoother.

Might want to distinquish loading versus starting. That way you can load behind the scenese and once loaded, show and start the ppt.

青巷忧颜 2024-11-14 10:37:36

在完成一些示例代码之后,我实现了一个后台工作人员来完成这个任务。有关详细信息 来自 msdn - 如何:使用后台工作者

我试图找到一种更可靠的方法来确保应用程序处理 F11 命令,但现在我在 SendKeys 之前放置了 Thread.Sleep。

请随时留下评论或问题。

[DllImport("user32.dll")]
    [return: MarshalAs(UnmanagedType.Bool)]
    static extern bool SetForegroundWindow(IntPtr hWnd);

    Process p;
    //Process p is initialized: p = Process.Start(@"<path\application.exe>");
    Form2 oForm;

 private void transition()
    {
        BackgroundWorker bw = new BackgroundWorker();
        oForm = new Form2();

        bw.DoWork += new DoWorkEventHandler(bw_DoWork);
        bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);
        oForm.Show();
        if (bw.IsBusy != true)
        {
            bw.RunWorkerAsync();
        }

    }
    private void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
    {       
        oForm.closethis();
    }
    private void bw_DoWork(object sender, DoWorkEventArgs e)
    {
        BackgroundWorker worker = sender as BackgroundWorker;

            if ((worker.CancellationPending == true))
            {
                e.Cancel = true;                   
            }
            else
            {                   
                SetForegroundWindow(p.MainWindowHandle);
                p.WaitForInputIdle(3000);
                System.Threading.Thread.Sleep(500);
                SendKeys.SendWait("{F11}");    
                //Sends the application into full screen mode           
            }

    }

以及淡入和淡出表单的代码..

public partial class Form2 : Form
{
    public Form2()
    {
        this.Visible = false;
        this.Opacity = 0;

        InitializeComponent();

        this.TopMost = true; 
        this.Visible = true;

        while (this.Opacity < 1)
        {
           this.Opacity += .05;
           Thread.Sleep(5);
           this.TopMost = true;
        }       
    }
    private void closefade()
    {
        while (this.Opacity > 0)
        {
            this.Opacity -= .05;
            Thread.Sleep(5);
            this.TopMost = true;
        }
        this.Close();
    }

    delegate void CloseBack();
    public void closethis()
    {
        if (this.InvokeRequired)
        {
            CloseBack b = new CloseBack(closethis);
        }
        else
            closefade();
    }
}

After working through some example code I implemented a background worker that did the trick. For more info From msdn - How to: Use a Background Worker.

I'm trying to find a more reliable way to ensure the F11 command is processed by the application, but for now I've put in a Thread.Sleep before the SendKeys.

Please feel free to leave comments or questions.

[DllImport("user32.dll")]
    [return: MarshalAs(UnmanagedType.Bool)]
    static extern bool SetForegroundWindow(IntPtr hWnd);

    Process p;
    //Process p is initialized: p = Process.Start(@"<path\application.exe>");
    Form2 oForm;

 private void transition()
    {
        BackgroundWorker bw = new BackgroundWorker();
        oForm = new Form2();

        bw.DoWork += new DoWorkEventHandler(bw_DoWork);
        bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);
        oForm.Show();
        if (bw.IsBusy != true)
        {
            bw.RunWorkerAsync();
        }

    }
    private void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
    {       
        oForm.closethis();
    }
    private void bw_DoWork(object sender, DoWorkEventArgs e)
    {
        BackgroundWorker worker = sender as BackgroundWorker;

            if ((worker.CancellationPending == true))
            {
                e.Cancel = true;                   
            }
            else
            {                   
                SetForegroundWindow(p.MainWindowHandle);
                p.WaitForInputIdle(3000);
                System.Threading.Thread.Sleep(500);
                SendKeys.SendWait("{F11}");    
                //Sends the application into full screen mode           
            }

    }

And the code for the form that fades in and out..

public partial class Form2 : Form
{
    public Form2()
    {
        this.Visible = false;
        this.Opacity = 0;

        InitializeComponent();

        this.TopMost = true; 
        this.Visible = true;

        while (this.Opacity < 1)
        {
           this.Opacity += .05;
           Thread.Sleep(5);
           this.TopMost = true;
        }       
    }
    private void closefade()
    {
        while (this.Opacity > 0)
        {
            this.Opacity -= .05;
            Thread.Sleep(5);
            this.TopMost = true;
        }
        this.Close();
    }

    delegate void CloseBack();
    public void closethis()
    {
        if (this.InvokeRequired)
        {
            CloseBack b = new CloseBack(closethis);
        }
        else
            closefade();
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文