-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclose_disabled.ps1
More file actions
111 lines (98 loc) · 3.7 KB
/
close_disabled.ps1
File metadata and controls
111 lines (98 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# based on: http://www.java2s.com/Tutorial/CSharp/0460__GUI-Windows-Forms/AsimpleBrowser.htm
add-Type @"
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
public class WebBrowserDemo {
[STAThread]
public static void Main() {
Application.EnableVisualStyles();
Application.Run(new Form1());
}
}
public class Form1 : Form {
private String localFile = @"file://c:\developer\sergueik\powershell_ui_samples\test.html";
// TODO: suppress warning CS0414:
// because add-Type : Warning as Error
private StatusStrip statusStrip1;
private ToolStripProgressBar toolStripProgressBar1;
private WebBrowser webBrowser1;
private void webBrowser1_ProgressChanged(object sender, WebBrowserProgressChangedEventArgs e) {
toolStripProgressBar1.Maximum = (int)e.MaximumProgress;
toolStripProgressBar1.Value = (int)e.CurrentProgress;
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) {
toolStripProgressBar1.Value = toolStripProgressBar1.Maximum;
}
public Form1() {
statusStrip1 = new StatusStrip();
toolStripProgressBar1 = new ToolStripProgressBar();
webBrowser1 = new WebBrowser();
statusStrip1.SuspendLayout();
SuspendLayout();
statusStrip1.Items.AddRange(new ToolStripItem[] {
toolStripProgressBar1
});
statusStrip1.LayoutStyle = ToolStripLayoutStyle.Table;
statusStrip1.Location = new System.Drawing.Point(0, 488);
statusStrip1.Name = "statusStrip1";
statusStrip1.Size = new System.Drawing.Size(695, 22);
statusStrip1.TabIndex = 0;
statusStrip1.Text = "statusStrip1";
toolStripProgressBar1.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText;
toolStripProgressBar1.Name = "toolStripProgressBar1";
toolStripProgressBar1.Size = new System.Drawing.Size(100, 15);
toolStripProgressBar1.Text = "toolStripProgressBar1";
webBrowser1.Dock = DockStyle.Fill;
webBrowser1.Location = new System.Drawing.Point(0, 0);
webBrowser1.Name = "webBrowser1";
webBrowser1.Size = new System.Drawing.Size(695, 488);
Console.Error.WriteLine("Loading uri: " + localFile);
try {
webBrowser1.Url = new System.Uri(localFile, System.UriKind.Absolute);
// https://stackoverflow.com/questions/17926197/open-local-file-in-system-windows-forms-webbrowser-control
// webBrowser1.DocumentText = pageContent;
} catch (UriFormatException e) {
Console.Error.WriteLine(e.ToString());
return;
} catch (NullReferenceException e) {
Console.Error.WriteLine(e.ToString());
return;
}
webBrowser1.ProgressChanged += new WebBrowserProgressChangedEventHandler(webBrowser1_ProgressChanged);
webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
AutoScaleDimensions = new SizeF(6F, 13F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(695, 510);
Controls.Add(webBrowser1);
Controls.Add(statusStrip1);
Name = "Form1";
Text = "Form1";
statusStrip1.ResumeLayout(false);
ResumeLayout(false);
PerformLayout();
}
// https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.webbrowser?view=netframework-4.0
// Navigates to the given URL if it is valid.
private void Navigate(String address) {
// TODO: better handle "relative URL"
var prefix = "file://";
if (String.IsNullOrEmpty(address))
return;
if (address.Equals("about:blank"))
return;
if (!address.StartsWith(prefix)) {
address = prefix + address;
}
try {
webBrowser1.Navigate(new Uri(address));
} catch (System.UriFormatException) {
return;
}
}
}
"@ -ReferencedAssemblies 'System.Data','System.Drawing','System.Windows.Forms.dll','System.Runtime.InteropServices.dll','System.Net.dll'