67 lines
1.6 KiB
C#
67 lines
1.6 KiB
C#
///
|
|
/// Copyright (c) 2013-2015 Sensus Metering Systems
|
|
///
|
|
using System;
|
|
using System.Windows.Forms;
|
|
using TBF.BenchControl.Generic;
|
|
|
|
namespace TBF
|
|
{
|
|
public partial class SelectComponentClassDlg : Form
|
|
{
|
|
/// This is the main result of this dialog
|
|
public IComponentFactory SlctdCmpntFactory = null;
|
|
|
|
int selectedIndex = -1;
|
|
|
|
/// Constructor
|
|
public SelectComponentClassDlg()
|
|
{
|
|
InitializeComponent();
|
|
|
|
foreach (var componentFactory in BenchControl.TbfComponents.Factories)
|
|
{
|
|
availCmpntsLstBox.Items.Add(componentFactory.ClassName);
|
|
}
|
|
}
|
|
|
|
/// Load components from BenchControl.SupportedComponents
|
|
private void SelectComponentClassDlg_Load(object sender, EventArgs e)
|
|
{
|
|
if (selectedIndex >= 0 && selectedIndex < BenchControl.TbfComponents.Factories.Count)
|
|
{
|
|
availCmpntsLstBox.SelectedIndex = selectedIndex;
|
|
}
|
|
}
|
|
|
|
/// Double click - Add the clicked component
|
|
private void availCmpntsLstBox_DoubleClick(object sender, EventArgs e)
|
|
{
|
|
okButton_Click(sender, e);
|
|
}
|
|
|
|
/// OK - Add the selected component
|
|
private void okButton_Click(object sender, EventArgs e)
|
|
{
|
|
int ix = availCmpntsLstBox.SelectedIndex;
|
|
if (ix >= 0 && ix < BenchControl.TbfComponents.Factories.Count)
|
|
{
|
|
selectedIndex = ix;
|
|
SlctdCmpntFactory = BenchControl.TbfComponents.Factories[ix];
|
|
DialogResult = DialogResult.OK;
|
|
Close();
|
|
return;
|
|
}
|
|
}
|
|
|
|
/// Cancel - Do nothing
|
|
private void cancelButton_Click(object sender, EventArgs e)
|
|
{
|
|
SlctdCmpntFactory = null;
|
|
DialogResult = DialogResult.Cancel;
|
|
Close();
|
|
return;
|
|
}
|
|
}
|
|
}
|