Initial winforms content migrated (#18)

* Merge winforms framework content to working branch (#14)

* Breadcrumb / TOC / Move net5 to net folder (#15)

* change path from net5 to net

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Add .net 5 winforms placeholder article (#16)

* added some metadata and adjusted net5 placeholder

* corrections

* corrections

* corrections

* Test1

* Swapping landing page vs concept

* fix links

* Fix links

* Fix desc
This commit is contained in:
Andy De George
2020-09-01 16:26:21 -07:00
committed by GitHub
parent 1a27c9b107
commit c0ba284473
1557 changed files with 129980 additions and 13 deletions
@@ -0,0 +1,62 @@
using System;
using System.Drawing;
using System.IO;
using System.Security;
using System.Windows.Forms;
public class OpenFileDialogForm : Form
{
[STAThread]
public static void Main()
{
Application.SetCompatibleTextRenderingDefault(false);
Application.EnableVisualStyles();
Application.Run(new OpenFileDialogForm());
}
private Button selectButton;
private OpenFileDialog openFileDialog1;
private TextBox textBox1;
public OpenFileDialogForm()
{
openFileDialog1 = new OpenFileDialog();
selectButton = new Button
{
Size = new Size(100, 20),
Location = new Point(15, 15),
Text = "Select file"
};
selectButton.Click += new EventHandler(SelectButton_Click);
textBox1 = new TextBox
{
Size = new Size(300, 300),
Location = new Point(15, 40),
Multiline = true,
ScrollBars = ScrollBars.Vertical
};
ClientSize = new Size(330, 360);
Controls.Add(selectButton);
Controls.Add(textBox1);
}
private void SetText(string text)
{
textBox1.Text = text;
}
private void SelectButton_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
try
{
var sr = new StreamReader(openFileDialog1.FileName);
SetText(sr.ReadToEnd());
}
catch (SecurityException ex)
{
MessageBox.Show($"Security error.\n\nError message: {ex.Message}\n\n" +
$"Details:\n\n{ex.StackTrace}");
}
}
}
}
@@ -0,0 +1,55 @@
Imports System.Drawing
Imports System.IO
Imports System.Security
Imports System.Windows.Forms
Public Class OpenFileDialogForm : Inherits Form
Public Shared Sub Main()
Application.SetCompatibleTextRenderingDefault(False)
Application.EnableVisualStyles()
Dim frm As New OpenFileDialogForm()
Application.Run(frm)
End Sub
Dim WithEvents SelectButton As Button
Dim openFileDialog1 As OpenFileDialog
Dim TextBox1 As TextBox
Private Sub New()
ClientSize = New Size(400, 400)
openFileDialog1 = New OpenFileDialog()
SelectButton = New Button()
With SelectButton
.Text = "Select file"
.Location = New Point(15, 15)
.Size = New Size(100, 25)
End With
TextBox1 = New TextBox()
With TextBox1
.Size = New Size(300, 300)
.Location = New Point(15, 50)
.Multiline = True
.ScrollBars = ScrollBars.Vertical
End With
Controls.Add(SelectButton)
Controls.Add(TextBox1)
End Sub
Private Sub SetText(text)
TextBox1.Text = text
End Sub
Public Sub SelectButton_Click(sender As Object, e As EventArgs) _
Handles SelectButton.Click
If openFileDialog1.ShowDialog() = DialogResult.OK Then
Try
Dim sr As New StreamReader(openFileDialog1.FileName)
SetText(sr.ReadToEnd())
Catch SecEx As SecurityException
MessageBox.Show($"Security error:{vbCrLf}{vbCrLf}{SecEx.Message}{vbCrLf}{vbCrLf}" &
$"Details:{vbCrLf}{vbCrLf}{SecEx.StackTrace}")
End Try
End If
End Sub
End Class
@@ -0,0 +1,60 @@
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Security;
using System.Windows.Forms;
public class OpenFileDialogForm : Form
{
[STAThread]
public static void Main()
{
Application.SetCompatibleTextRenderingDefault(false);
Application.EnableVisualStyles();
Application.Run(new OpenFileDialogForm());
}
private Button selectButton;
private OpenFileDialog openFileDialog1;
public OpenFileDialogForm()
{
openFileDialog1 = new OpenFileDialog()
{
FileName = "Select a text file",
Filter = "Text files (*.txt)|*.txt",
Title = "Open text file"
};
selectButton = new Button()
{
Size = new Size(100, 20),
Location = new Point(15, 15),
Text = "Select file"
};
selectButton.Click += new EventHandler(selectButton_Click);
Controls.Add(selectButton);
}
private void selectButton_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
try
{
var filePath = openFileDialog1.FileName;
using (Stream str = openFileDialog1.OpenFile())
{
Process.Start("notepad.exe", filePath);
}
}
catch (SecurityException ex)
{
MessageBox.Show($"Security error.\n\nError message: {ex.Message}\n\n" +
$"Details:\n\n{ex.StackTrace}");
}
}
}
}
@@ -0,0 +1,44 @@
Imports System.ComponentModel
Imports System.Diagnostics
Imports System.IO
Imports System.Security
Imports System.Windows.Forms
Public Class OpenFileDialogForm : Inherits Form
Dim WithEvents selectButton As Button
Dim openFileDialog1 As OpenFileDialog
Public Shared Sub Main()
Application.SetCompatibleTextRenderingDefault(false)
Application.EnableVisualStyles()
Dim frm As New OpenFileDialogForm()
Application.Run(frm)
End Sub
Private Sub New()
openFileDialog1 = New OpenFileDialog() With
{
.FileName = "Select a text file",
.Filter = "Text files (*.txt)|*.txt",
.Title = "Open text file"
}
selectButton = New Button() With {.Text = "Select file"}
Controls.Add(selectButton)
End Sub
Public Sub selectButton_Click(sender As Object, e As EventArgs) _
Handles selectButton.Click
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
Try
Dim filePath = OpenFileDialog1.FileName
Using str = openFileDialog1.OpenFile()
Process.Start("notepad.exe", filePath)
End Using
Catch SecEx As SecurityException
MessageBox.Show($"Security error:{vbCrLf}{vbCrLf}{SecEx.Message}{vbCrLf}{vbCrLf}" &
$"Details:{vbCrLf}{vbCrLf}{SecEx.StackTrace}")
End Try
End If
End Sub
End Class
@@ -0,0 +1,62 @@
using System;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;
public class InvokeThreadSafeForm : Form
{
private delegate void SafeCallDelegate(string text);
private Button button1;
private TextBox textBox1;
private Thread thread2 = null;
[STAThread]
static void Main()
{
Application.SetCompatibleTextRenderingDefault(false);
Application.EnableVisualStyles();
Application.Run(new InvokeThreadSafeForm());
}
public InvokeThreadSafeForm()
{
button1 = new Button
{
Location = new Point(15, 55),
Size = new Size(240, 20),
Text = "Set text safely"
};
button1.Click += new EventHandler(Button1_Click);
textBox1 = new TextBox
{
Location = new Point(15, 15),
Size = new Size(240, 20)
};
Controls.Add(button1);
Controls.Add(textBox1);
}
private void Button1_Click(object sender, EventArgs e)
{
thread2 = new Thread(new ThreadStart(SetText));
thread2.Start();
Thread.Sleep(1000);
}
private void WriteTextSafe(string text)
{
if (textBox1.InvokeRequired)
{
var d = new SafeCallDelegate(WriteTextSafe);
textBox1.Invoke(d, new object[] { text });
}
else
{
textBox1.Text = text;
}
}
private void SetText()
{
WriteTextSafe("This text was set safely.");
}
}
@@ -0,0 +1,54 @@
Imports System.Drawing
Imports System.Threading
Imports System.Windows.Forms
Public Class InvokeThreadSafeForm : Inherits Form
Public Shared Sub Main()
Application.SetCompatibleTextRenderingDefault(False)
Application.EnableVisualStyles()
Dim frm As New InvokeThreadSafeForm()
Application.Run(frm)
End Sub
Dim WithEvents Button1 As Button
Dim TextBox1 As TextBox
Dim Thread2 as Thread = Nothing
Delegate Sub SafeCallDelegate(text As String)
Private Sub New()
Button1 = New Button()
With Button1
.Location = New Point(15, 55)
.Size = New Size(240, 20)
.Text = "Set text safely"
End With
TextBox1 = New TextBox()
With TextBox1
.Location = New Point(15, 15)
.Size = New Size(240, 20)
End With
Controls.Add(Button1)
Controls.Add(TextBox1)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Thread2 = New Thread(New ThreadStart(AddressOf SetText))
Thread2.Start()
Thread.Sleep(1000)
End Sub
Private Sub WriteTextSafe(text As String)
If TextBox1.InvokeRequired Then
Dim d As New SafeCallDelegate(AddressOf SetText)
TextBox1.Invoke(d, New Object() {text})
Else
TextBox1.Text = text
End If
End Sub
Private Sub SetText()
WriteTextSafe("This text was set safely.")
End Sub
End Class
@@ -0,0 +1,56 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;
public class BackgroundWorkerForm : Form
{
private BackgroundWorker backgroundWorker1;
private Button button1;
private TextBox textBox1;
[STAThread]
static void Main()
{
Application.SetCompatibleTextRenderingDefault(false);
Application.EnableVisualStyles();
Application.Run(new BackgroundWorkerForm());
}
public BackgroundWorkerForm()
{
backgroundWorker1 = new BackgroundWorker();
backgroundWorker1.DoWork += new DoWorkEventHandler(BackgroundWorker1_DoWork);
backgroundWorker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(BackgroundWorker1_RunWorkerCompleted);
button1 = new Button
{
Location = new Point(15, 55),
Size = new Size(240, 20),
Text = "Set text safely with BackgroundWorker"
};
button1.Click += new EventHandler(Button1_Click);
textBox1 = new TextBox
{
Location = new Point(15, 15),
Size = new Size(240, 20)
};
Controls.Add(button1);
Controls.Add(textBox1);
}
private void Button1_Click(object sender, EventArgs e)
{
backgroundWorker1.RunWorkerAsync();
}
private void BackgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
// Sleep 2 seconds to emulate getting data.
Thread.Sleep(2000);
e.Result = "This text was set safely by BackgroundWorker.";
}
private void BackgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
textBox1.Text = e.Result.ToString();
}
}
@@ -0,0 +1,51 @@
Imports System.ComponentModel
Imports System.Drawing
Imports System.Threading
Imports System.Windows.Forms
Public Class BackgroundWorkerForm : Inherits Form
Public Shared Sub Main()
Application.SetCompatibleTextRenderingDefault(False)
Application.EnableVisualStyles()
Dim frm As New BackgroundWorkerForm()
Application.Run(frm)
End Sub
Dim WithEvents BackgroundWorker1 As BackgroundWorker
Dim WithEvents Button1 As Button
Dim TextBox1 As TextBox
Private Sub New()
BackgroundWorker1 = New BackgroundWorker()
Button1 = New Button()
With Button1
.Text = "Set text safely with BackgroundWorker"
.Location = New Point(15, 55)
.Size = New Size(240, 20)
End With
TextBox1 = New TextBox()
With TextBox1
.Location = New Point(15, 15)
.Size = New Size(240, 20)
End With
Controls.Add(Button1)
Controls.Add(TextBox1)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
BackgroundWorker1.RunWorkerAsync()
End Sub
Private Sub BackgroundWorker1_DoWork(sender As Object, e As DoWorkEventArgs) _
Handles BackgroundWorker1.DoWork
' Sleep 2 seconds to emulate getting data.
Thread.Sleep(2000)
e.Result = "This text was set safely by BackgroundWorker."
End Sub
Private Sub BackgroundWorker1_RunWorkerCompleted(sender As Object, e As RunWorkerCompletedEventArgs) _
Handles BackgroundWorker1.RunWorkerCompleted
textBox1.Text = e.Result.ToString()
End Sub
End Class