Alessandro Del Sole's Blog

{ A programming space about Microsoft® .NET® }

  Home :: Contact :: Syndication  :: Login
  73 Posts :: 10 Stories :: 141 Comments :: 1729 Trackbacks

News

Your host

This is me! This space is about Microsoft® .NET® and Microsoft® Visual Basic development. Enjoy! :-)

These postings are provided 'AS IS' for entertainment purposes only with absolutely no warranty expressed or implied and confer no rights.

Microsoft MVP

My MVP Profile

I'm a VB!

Watch my interview in Seattle

My new book on VB 2010

Order my book about VB 2010 on Amazon My book "Visual Basic 2010 Unleashed" is available. Click the cover!

Your visits

Windows Live Alerts

Vsi Builder 2008

My tool for VS 2005/2008 Download Vsi Builder, my dev tool for Visual Studio 2005/2008!

Add me to MSDN Social!

Follow me on Twitter!

Messenger me!


Grab this badge here!

CyberInstaller Beta Tester

Download CIS 2008!!

CodePlex download Download my open-source projects from CodePlex!

Search the blog



Article Categories

Archives

Post Categories

.NET Framework

Blogroll

Help Authoring

Microsoft & MSDN

Setup & Deployment

Visual Basic 2005/2008/2010

Did you ever try to download a file from the Internet with Windows 7? If yes, maybe you noticed that the Internet Explorer icon in the task bar shows the download progress, like a classic ProgressBar. With WPF 4 and VB (o C#) 2010 it's possible programming this interesting functionality in order to make our applications able of showing the progress state of a given task. The code example shown in this blog post simply wastes some time in an asynchronous way so that it can send progress state to a ProgressBar control and to the icon in the task bar (the reason about this is that the focus is understanding how the progress bar works, not providing complex code). For the sake of completeness, I took some tips from this blog post by Pete Brown, that I revisited in a VB fashion.

On the XAML side, first we need the usual reference to the task bar, then we can add a ProgressBar inside the Window:

    <Window.TaskbarItemInfo>

        <TaskbarItemInfo/>

    </Window.TaskbarItemInfo>

    <Grid>

        <ProgressBar Name="ProgressBar1" Height="40" Margin="5"/>

    </Grid>

Next, let's write some VB code which makes use of a BackgroundWorker control to make async operations, whose progress will be reported on both the task bar and on the ProgressBar. The following code demonstrates how wasting your time and how you can send the progress to the task bar at the same time:

Class MainWindow

    Private Sub MainWindow_Loaded(ByVal sender As Object,

                                  ByVal e As RoutedEventArgs) Handles Me.Loaded

 

        Dim worker As New System.ComponentModel.BackgroundWorker

 

        AddHandler worker.DoWork, AddressOf WasteSomeTime

        AddHandler worker.ProgressChanged, AddressOf worker_ProgressChanged

        AddHandler worker.RunWorkerCompleted, AddressOf worker_RunWorkerCompleted

 

        worker.WorkerReportsProgress = True

 

        'Set the progress state as "normal"

        TaskbarItemInfo.ProgressState = Shell.TaskbarItemProgressState.Normal

 

        'Start the work

        worker.RunWorkerAsync()

    End Sub

 

    'Waste some time, simulating some work

    Private Sub WasteSomeTime(ByVal sender As Object,

    ByVal e As System.ComponentModel.DoWorkEventArgs)

        For i As Integer = 0 To 99 Step 10

            System.Threading.Thread.Sleep(1000)

 

            'Raises the ProgressChanged event passing the value

            CType(sender, System.ComponentModel.BackgroundWorker).ReportProgress(i)

        Next i

    End Sub

 

    'Finally set values for controls

    Private Sub worker_RunWorkerCompleted(ByVal sender As Object,

                                          ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs)

        ProgressBar1.Value = 100

        TaskbarItemInfo.ProgressValue = 1.0

    End Sub

 

    'Increment the control's progress value

    Private Sub worker_ProgressChanged(ByVal sender As Object,

                                       ByVal e As System.ComponentModel.ProgressChangedEventArgs)

        ProgressBar1.Value = e.ProgressPercentage

        TaskbarItemInfo.ProgressValue = CDbl(e.ProgressPercentage) / 100

    End Sub

End Class

The following are the most two interesting lines of code from all the one shown above. The first line:

        'Set the progress state as "normal"

        TaskbarItemInfo.ProgressState = Shell.TaskbarItemProgressState.Normal

Here the code tells the icon on the task bar that the progress bar will have a normal aspect, which is green. Other choices are available from the Shell.TaskBarItemProgressState enumeration, which allow to customize the progress bar aspect. For instance, Error will make the progress state's color as red, Paused as yellow, while Indeterminate will represent the progress state as a loop; this is typical when you want to represent an idle state or a freezed task.

This is instead the second interesting line:

TaskbarItemInfo.ProgressValue = 1.0

Here we just assign to the ProgressValue property the value that represents the progress state. This is a moment of what we get on the task bar:

By the way, such feature consumes some more system resources so you should use it carefully. The source code accompanying this blog post is available from the MSDN Code Gallery here.

Finally, I'd like to mention that there are lots of other ways (and resources) for programming Windows 7 with managed code, not necessarily related to WPF 4. If you are interested in this kind of development, have a look at the Windows API Code Pack which provides managed access to lots of features of the new operating system and that can be also used with Visual Studio 2008.

Alessandro

posted on Friday, January 29, 2010 4:42 PM

Feedback

# Windows 7 &amp; WPF 4: using task bar icons like progress bars | BlogBov 1/29/2010 7:33 PM Pingback/TrackBack
Windows 7 &amp; WPF 4: using task bar icons like progress bars | BlogBov

#  Windows 7 &amp; WPF 4: using task bar icons like progress bars | GetVB.com 1/29/2010 8:43 PM Pingback/TrackBack
Windows 7 &amp; WPF 4: using task bar icons like progress bars | GetVB.com

# Windows 7 &amp; WPF 4: using task bar icons like progress bars | Drakz Free Online Service 1/29/2010 10:15 PM Pingback/TrackBack
Windows 7 &amp; WPF 4: using task bar icons like progress bars | Drakz Free Online Service

# Windows 7 &amp; WPF 4: using task bar icons like progress bars | Drakz Free Online Service 1/29/2010 10:15 PM Pingback/TrackBack
Windows 7 &amp; WPF 4: using task bar icons like progress bars | Drakz Free Online Service

# noneed.info &raquo; Blog Archive &raquo; Windows 7 &amp; WPF 4: using task bar icons like progress bars 1/30/2010 3:07 AM Pingback/TrackBack
noneed.info &raquo; Blog Archive &raquo; Windows 7 &amp; WPF 4: using task bar icons like progress bars

#  Windows 7 &amp; WPF 4: using task bar icons like progress bars : News IT 1/30/2010 3:51 AM Pingback/TrackBack
Windows 7 &amp; WPF 4: using task bar icons like progress bars : News IT

# Windows 7 &amp; WPF 4: using task bar icons like progress bars 1/30/2010 4:21 AM Pingback/TrackBack
Windows 7 &amp; WPF 4: using task bar icons like progress bars

# Windows 7 &amp; WPF 4: using task bar icons like progress bars | Drakz windows Online Service 1/30/2010 4:53 AM Pingback/TrackBack
Windows 7 &amp; WPF 4: using task bar icons like progress bars | Drakz windows Online Service

# Windows 7 &amp; WPF 4: using task bar icons like progress bars | Drakz windows Online Service 1/30/2010 4:53 AM Pingback/TrackBack
Windows 7 &amp; WPF 4: using task bar icons like progress bars | Drakz windows Online Service

# Windows 7 &amp; WPF 4: using task bar icons like progress bars | Drakz windows Online Service 1/30/2010 4:53 AM Pingback/TrackBack
Windows 7 &amp; WPF 4: using task bar icons like progress bars | Drakz windows Online Service

# Windows 7 &amp; WPF 4: using task bar icons like progress bars | Drakz windows Online Service 1/30/2010 4:54 AM Pingback/TrackBack
Windows 7 &amp; WPF 4: using task bar icons like progress bars | Drakz windows Online Service

# re: Windows 7 & WPF 4: using task bar icons like progress bars 7/21/2010 10:30 AM Cheap Thomas Sabo Schmuck On Sale
The Napier long chain and white glass beads necklace is an interesting piece and is a fine example of beautiful bead jewellery. Beads were used to good effect in jewelry from Napier. You could by different pieces of bead jewellery and still end up with a whole set that is matching.

There are several other kinds of jewellery from Napier. Among the more exotic jewellery from Napier is the turquoise jewellery they had in their portfolio. An example of this is the Napier goldtone and turquoise beaded necklace.

Jewellery from Napier is a fine example of vintage jewellery. The makers of Napier jewellery considered their jewellery well above the conventional costume jewellery. They considered their jewellery to be fashion jewellery. If you are to buy jewellery from Napier, then instead of vintage costume jewellery, you would have vintage fashion jewellery. These items are fine pieces that you can show off at parties and other high end social gatherings. You can be the person that stands out from the crowd because of the fine jewellery from Napier that you wear.





Post Feedback

Title:
Name:
Url:
Comments: 
Codice di sicurezza
Protected by FormShield