tbf/TestBenchFramework/SelectComponentClassDlg.cs

78 lines
1.8 KiB
C#
Raw Normal View History

///
/// Copyright (c) 2013-2015 Sensus Metering Systems
///
using System;
using System.Windows.Forms;
using TBF.BenchControl.Generic;
using TBF.Resources;
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
2014-12-29 23:17:45 +00:00
private void SelectComponentClassDlg_Load(object sender, EventArgs e)
{
Localize();
if (selectedIndex >= 0 && selectedIndex < BenchControl.TbfComponents.Factories.Count)
{
availCmpntsLstBox.SelectedIndex = selectedIndex;
}
}
void Localize()
{
Text = Strings.Select_Component;
availableComponentsLabel.Text = Strings.Available_Components_;
okButton.Text = Strings.OkBtnText;
cancelButton.Text = Strings.CancelBtnText;
}
/// 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;
}
}
}