Windows 7任务栏进度

时间:2009-11-18 19:46:31

标签: c# wpf windows-7 taskbar

快速提问,我为Windows 7开发了一个特定于论坛的C#WPF WebBrowser。

到目前为止,我已完成任务栏:

选项卡式缩略图

跳转列表

图标叠加

现在,当WebBrowser在启动下载时使用IE引擎时,会显示进度对话框,我想要的是将进度反映在我的应用程序的任务栏按钮中。

这是否适合?感谢

2 个答案:

答案 0 :(得分:4)

我相信这是Scott Hanselman covered in one of his weekly source code blogs

不确定这是不是你想要的。

答案 1 :(得分:1)

我知道如何把它放在任务栏中,我只需要抓住下载进度,这样我就可以在任务栏中显示进度。下面是我如何获得它来显示导航的片段,文件副本显示而不需要代码,shell会自动拾取它。

  #region Background Worker

    void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
    {
        this.TaskbarItemInfo.ProgressValue = (double)e.ProgressPercentage / 100;

    }

    void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
    {
        if (e.Cancelled == true)
        {
            this.TaskbarItemInfo.ProgressState = TaskbarItemProgressState.Paused;
        }
        else if (e.Error != null)
        {
            this.TaskbarItemInfo.ProgressState = TaskbarItemProgressState.Error;
        }
        else
        {
            this.TaskbarItemInfo.ProgressState = TaskbarItemProgressState.None;
        }
    }

    void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
    {
        for (int i = 1; i <= 100; i++)
        {
            Thread.Sleep(100);

            this.backgroundWorker1.ReportProgress(i,i.ToString());
        }
            }
        }
    }

    #endregion

导航所需的全部内容是:

 private void Browser_Navigated(object sender, WebBrowserNavigatedEventArgs e)
    {
        if (backgroundWorker1.IsBusy == false)
        {
            backgroundWorker1.RunWorkerAsync();

            TaskbarItemInfo.ProgressState = TaskbarItemProgressState.Normal;
        }

        if (tabControl1.TabPages.Count > 10 && tabControl1.SelectedTab != null)
            UpdatePreviewBitmap(tabControl1.SelectedTab);

取自Window Load Event:

        this.backgroundWorker1.WorkerReportsProgress = true;
        this.backgroundWorker1.WorkerSupportsCancellation = true;
        this.backgroundWorker1.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork);
        this.backgroundWorker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker1_RunWorkerCompleted);
        this.backgroundWorker1.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker1_ProgressChanged);

        //
        TabbedThumbnail preview = new TabbedThumbnail(this.Handle, tabPage.Handle);
        //
        preview.TabbedThumbnailActivated += new EventHandler<TabbedThumbnailEventArgs>(preview_TabbedThumbnailActivated);
        preview.TabbedThumbnailClosed += new EventHandler<TabbedThumbnailEventArgs>(preview_TabbedThumbnailClosed);
        preview.TabbedThumbnailMaximized += new EventHandler<TabbedThumbnailEventArgs>(preview_TabbedThumbnailMaximized);
        preview.TabbedThumbnailMinimized += new EventHandler<TabbedThumbnailEventArgs>(preview_TabbedThumbnailMinimized);
        //
        TaskbarManager.Instance.TabbedThumbnail.AddThumbnailPreview(preview);
        //
        tabControl1.SelectedTab = tabPage;
        TaskbarManager.Instance.TabbedThumbnail.SetActiveTab(tabControl1.SelectedTab);
        //

        scrollEventAdded = false;

希望这是有道理的。感谢