1'
2' MyProgressDialog.vb
3'
4' Authors:
5'   Rolf Bjarne Kvinge (RKvinge@novell.com>
6'
7' Copyright (C) 2007 Novell (http://www.novell.com)
8'
9' Permission is hereby granted, free of charge, to any person obtaining
10' a copy of this software and associated documentation files (the
11' "Software"), to deal in the Software without restriction, including
12' without limitation the rights to use, copy, modify, merge, publish,
13' distribute, sublicense, and/or sell copies of the Software, and to
14' permit persons to whom the Software is furnished to do so, subject to
15' the following conditions:
16'
17' The above copyright notice and this permission notice shall be
18' included in all copies or substantial portions of the Software.
19'
20' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21' EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22' MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23' NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24' LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25' OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26' WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27'
28#If TARGET_JVM = False Then 'Windows.Forms Not Supported by Grasshopper
29
30Imports System.Net
31
32Namespace Microsoft.VisualBasic.Devices
33    Friend Class MyProgressDialog
34        Inherits System.Windows.Forms.Form
35
36        Private WithEvents m_Client As Net.WebClient
37
38        Sub New(ByVal Client As Net.WebClient, ByVal Status As String)
39            m_Client = Client
40            lblStatus.Text = Status
41        End Sub
42
43        Protected Overrides Sub Dispose(ByVal disposing As Boolean)
44            If disposing AndAlso components IsNot Nothing Then
45                components.Dispose()
46            End If
47            MyBase.Dispose(disposing)
48        End Sub
49
50        Friend WithEvents cmdCancel As System.Windows.Forms.Button
51        Friend WithEvents barProgress As System.Windows.Forms.ProgressBar
52        Friend WithEvents lblStatus As System.Windows.Forms.Label
53
54        Private components As System.ComponentModel.IContainer
55
56        <System.Diagnostics.DebuggerStepThrough()> _
57        Private Sub InitializeComponent()
58            Me.cmdCancel = New System.Windows.Forms.Button
59            Me.barProgress = New System.Windows.Forms.ProgressBar
60            Me.lblStatus = New System.Windows.Forms.Label
61            Me.SuspendLayout()
62            '
63            'cmdCancel
64            '
65            Me.cmdCancel.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
66            Me.cmdCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
67            Me.cmdCancel.Location = New System.Drawing.Point(290, 118)
68            Me.cmdCancel.Name = "cmdCancel"
69            Me.cmdCancel.Size = New System.Drawing.Size(75, 23)
70            Me.cmdCancel.TabIndex = 0
71            Me.cmdCancel.Text = "Button1"
72            Me.cmdCancel.UseVisualStyleBackColor = True
73            '
74            'barProgress
75            '
76            Me.barProgress.Anchor = CType(((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left) _
77                        Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
78            Me.barProgress.Location = New System.Drawing.Point(12, 92)
79            Me.barProgress.Name = "barProgress"
80            Me.barProgress.Size = New System.Drawing.Size(353, 20)
81            Me.barProgress.TabIndex = 1
82            '
83            'lblStatus
84            '
85            Me.lblStatus.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
86                        Or System.Windows.Forms.AnchorStyles.Left) _
87                        Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
88            Me.lblStatus.Location = New System.Drawing.Point(12, 9)
89            Me.lblStatus.Name = "lblStatus"
90            Me.lblStatus.Size = New System.Drawing.Size(353, 80)
91            Me.lblStatus.TabIndex = 2
92            Me.lblStatus.Text = "Label1"
93            '
94            'NetworkProgressDialog
95            '
96            Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
97            Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
98            Me.CancelButton = Me.cmdCancel
99            Me.ClientSize = New System.Drawing.Size(377, 153)
100            Me.Controls.Add(Me.lblStatus)
101            Me.Controls.Add(Me.barProgress)
102            Me.Controls.Add(Me.cmdCancel)
103            Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
104            Me.MaximizeBox = False
105            Me.MinimizeBox = False
106            Me.Name = "NetworkProgressDialog"
107            Me.ShowInTaskbar = False
108            Me.Text = "Working..."
109            Me.ResumeLayout(False)
110
111        End Sub
112
113        Private Sub m_Client_DownloadFileCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs) Handles m_Client.DownloadFileCompleted
114            barProgress.Value = 100
115            Me.DialogResult = Windows.Forms.DialogResult.OK
116            Close()
117        End Sub
118
119        Private Sub m_Client_DownloadProgressChanged(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs) Handles m_Client.DownloadProgressChanged
120            barProgress.Value = e.ProgressPercentage
121        End Sub
122
123        Private Sub m_Client_UploadFileCompleted(ByVal sender As Object, ByVal e As System.Net.UploadFileCompletedEventArgs) Handles m_Client.UploadFileCompleted
124            barProgress.Value = 100
125            Me.DialogResult = Windows.Forms.DialogResult.OK
126            Close()
127        End Sub
128
129        Private Sub m_Client_UploadProgressChanged(ByVal sender As Object, ByVal e As System.Net.UploadProgressChangedEventArgs) Handles m_Client.UploadProgressChanged
130            barProgress.Value = e.ProgressPercentage
131        End Sub
132
133        Private Sub cmdCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdCancel.Click
134            m_Client.CancelAsync()
135            Me.DialogResult = Windows.Forms.DialogResult.Cancel
136            Close()
137        End Sub
138    End Class
139End Namespace
140#End If
141