|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows.Forms;
using AssemblyLoader;
using PanelFactory;
namespace DemoClientApp
{
public partial class MainForm : Form
{
AbstractPanelFactory factory = null;
Panel panel;
public MainForm()
{
InitializeComponent();
}
private void MainForm_Load(object sender, EventArgs e)
{
var binDebug = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var panelFactoryPluginFile = SearchPanelFactoryPlugin(binDebug);
if (panelFactoryPluginFile == string.Empty)
{
MessageBox.Show("No Plugin Found.");
}
Loader.ResolveAssembly = true;
var pluginAssembly = Loader.LoadAssembly(panelFactoryPluginFile);
foreach (var type in pluginAssembly.GetTypes())
{
if (type.IsAbstract == false)
{
if (type.IsClass)
{
if (type.BaseType == typeof(AbstractPanelFactory))
{
factory = pluginAssembly.CreateInstance(type.FullName) as AbstractPanelFactory;
}
}
}
}
}
private string SearchPanelFactoryPlugin(string pluginFolder)
{
pluginFolder = pluginFolder + "\\PlugIns";
var dllFiles = Directory.GetFiles(pluginFolder, "*.dll");
foreach (var dll in dllFiles)
{
if (Path.GetFileName(dll) != "AbstractPanelFactory.dll")
if (dll.EndsWith("PanelFactory.dll"))
{
return dll;
}
}
return string.Empty;
}
private void btnGetPanel_Click(object sender, EventArgs e)
{
if (factory == null)
{
MessageBox.Show(" Unable to find plugin.");
}
if (colorDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
Color selectedColor = colorDialog1.Color;
this.Controls.Remove(panel);
panel = factory.GetPanel(selectedColor);
panel.Dock = DockStyle.Fill;
this.Controls.Add(panel);
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.