サンプル
UserPropertyPage.cs
UserControl/TextBox1, TextBox2
using System.Windows.Forms;
using Microsoft.ManagementConsole;
using Microsoft.ManagementConsole.Advanced;
namespace SimpleSampleMmc
{
/// <summary>
/// Gets Name and textBox2
/// </summary>
public partial class UserPropertiesControl : UserControl
{
/// <summary>
/// Parent property page to expose data and state of property sheet
/// </summary>
private UserPropertyPage userPropertyPage;
/// <summary>
/// Constructor
/// </summary>
/// <param name="parentPropertyPage">Container property page for the control</param>
public UserPropertiesControl(UserPropertyPage parentPropertyPage)
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
// keep reference to parent
userPropertyPage = parentPropertyPage;
}
/// <summary>
/// Populate control values from the SelectionObject (set in UserListView.SelectionOnChanged)
/// </summary>
public void RefreshData(ResultNode userNode)
{
this.textBox1.Text = userNode.DisplayName;
this.textBox2.Text = userNode.SubItemDisplayNames[0]; // first subitem
userPropertyPage.Dirty = false;
}
/// <summary>
/// Update the node with the controls values
/// </summary>
/// <param name="userNode">Node being updated by property page</param>
public void UpdateData(ResultNode userNode)
{
userNode.DisplayName = this.textBox1.Text;
userNode.SubItemDisplayNames[0] = this.textBox2.Text; // first subitem
userPropertyPage.Dirty = false;
}
/// <summary>
/// Check during UserProptertyPage.OnApply to ensure that changes can be Applied
/// </summary>
/// <returns>returns true if changes are valid</returns>
public bool CanApplyChanges()
{
bool result = false;
if (textBox1.Text.Trim().Length == 0)
{
MessageBoxParameters messageBoxParameters = new MessageBoxParameters();
messageBoxParameters.Text = "Name cannot be blank";
userPropertyPage.ParentSheet.ShowDialog(messageBoxParameters);
}
else if (textBox2.Text.Trim().Length == 0)
{
MessageBoxParameters messageBoxParameters = new MessageBoxParameters();
messageBoxParameters.Text = "textBox2 cannot be blank";
userPropertyPage.ParentSheet.ShowDialog(messageBoxParameters);
}
else
{
result = true;
}
return result;
}
/// <summary>
/// Notifies the PropertyPage that info has changed and that the PropertySheet can change the
/// buttons
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void textBox1_TextChanged(object sender, System.EventArgs e)
{
userPropertyPage.Dirty = true;
}
/// <summary>
/// Notifies the PropertyPage that info has changed and that the PropertySheet can change the
/// buttons
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void textBox2_TextChanged(object sender, System.EventArgs e)
{
userPropertyPage.Dirty = true;
}
}
}