Assigning fields to controls

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.
 
V

Val Savvateev

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top