forked from naudio/NAudio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainForm.cs
61 lines (52 loc) · 1.91 KB
/
MainForm.cs
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
using System;
using System.Linq;
using System.Reflection;
using System.Runtime.Versioning;
using System.Windows.Forms;
using NAudioDemo.Utils;
namespace NAudioDemo
{
public sealed partial class MainForm : Form
{
private INAudioDemoPlugin currentPlugin;
public MainForm()
{
// use reflection to find all the demos
var demos = ReflectionHelper.CreateAllInstancesOf<INAudioDemoPlugin>().OrderBy(d => d.Name);
InitializeComponent();
listBoxDemos.DisplayMember = "Name";
foreach (var demo in demos)
{
listBoxDemos.Items.Add(demo);
}
var arch = Environment.Is64BitProcess ? "x64" : "x86";
var framework = ((TargetFrameworkAttribute)(Assembly.GetEntryAssembly().GetCustomAttributes(typeof(TargetFrameworkAttribute),true).ToArray()[0])).FrameworkName;
this.Text = $"{this.Text} ({framework}) ({arch})";
}
private void OnLoadDemoClick(object sender, EventArgs e)
{
var plugin = (INAudioDemoPlugin)listBoxDemos.SelectedItem;
if (plugin == currentPlugin) return;
currentPlugin = plugin;
DisposeCurrentDemo();
var control = plugin.CreatePanel();
control.Dock = DockStyle.Fill;
panelDemo.Controls.Add(control);
}
private void DisposeCurrentDemo()
{
if (panelDemo.Controls.Count <= 0) return;
panelDemo.Controls[0].Dispose();
panelDemo.Controls.Clear();
GC.Collect();
}
private void OnListBoxDemosDoubleClick(object sender, EventArgs e)
{
OnLoadDemoClick(sender, e);
}
private void OnMainFormClosing(object sender, FormClosingEventArgs e)
{
DisposeCurrentDemo();
}
}
}