Assigning fields to controls

  • Thread starter Thread starter Jesper DK
  • Start date Start date
J

Jesper DK

Hi,

I'm making a 'settings dialog' for my program with a
seperate form and the ShowDialog(). However, initializing
the controls with values, writing eventhandlers to store
changes when e.g a checkbox is checked - is a little
cumbersome. I remember when programming in MFC that there
were a great way of assigning a member variable to a
control - e.g a checkbox to a bool - using the class
wizard in visual studio 6 - so that the state of the bool
and checkbox were in sync controlled by code written by
VS. Is there some technique to doing this in .NET.

Thanks.
Jesper.
 
You could create properties on the form's class, that would set the
controls' values. For instance:

class MyFrom
{
private CheckBox userIsAgreeCheckBox;
......
public bool UserIsAgree
{
get { return userIsAgreeCheckBox.IsChecked; }
set { userIsAgreeCheckBox.IsChecked = value; }
}
}

When you need to setup and show the form:

MyForm myForm = new MyForm();

myForm.UserIsAgree = false;

DialogResult result = myForm.ShowDialog();

if ((result == DialogResult.OK) && myForm.UserIsAgree)
FormatDrive("C:");


:)
Regards.
 
Back
Top