Skip to content

Commit

Permalink
Added Windows.Forms.App to UnitTest to help test visual controls
Browse files Browse the repository at this point in the history
  • Loading branch information
dahall committed Nov 25, 2019
1 parent 4264357 commit 2c64bbf
Show file tree
Hide file tree
Showing 11 changed files with 887 additions and 0 deletions.
282 changes: 282 additions & 0 deletions UnitTests/Windows.Forms.App/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions UnitTests/Windows.Forms.App/Form1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Windows.Forms;

namespace Windows.Forms.App
{
public partial class Form1 : Form
{
private object currentDlg;

public Form1()
{
InitializeComponent();
FillComboWithDialogs(dlgCombo);
}

private static void FillComboWithDialogs(ComboBox cb) => cb.Items.AddRange(Assembly.GetAssembly(typeof(Vanara.Windows.Forms.AccessControlEditorDialog)).GetTypes().Where(t => !t.IsNested && typeof(CommonDialog).IsAssignableFrom(t) || typeof(Form).IsAssignableFrom(t)).ToArray());

private void button1_Click(object sender, EventArgs e)
{
if (currentDlg is null) return;
try
{
if (currentDlg is CommonDialog c)
c.ShowDialog();
else if (currentDlg is Form f)
f.ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), null, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

private void dlgCombo_SelectedIndexChanged(object sender, EventArgs e)
{
currentDlg = dlgCombo.SelectedItem is null ? null : Activator.CreateInstance((Type)dlgCombo.SelectedItem);
propertyGrid1.SelectedObject = currentDlg;
}
}
}
Loading

0 comments on commit 2c64bbf

Please sign in to comment.