I'm fairly new to c#, and I am just trying to work out how a
'properties' dialog works.
Currently in my code, I have an object represented by the class 'Dog'.
The dog object has several properties.
I have added a new windows form, class 'DogProperties' . I'm attempting
to use this to allow the user to edit the properties of an instance of
'Dog'.
To do this, I'm passing an instance of 'Dog' as a ref parameter to the
constructor of 'DogProperties' . The problem is, updated properties can
not be sent back, as the ref is only valid for the constructor.
An example of the existing code I have would be
// Create an instance of our properties dialog
DogProperties propertyDialog = new DogProperties(r ef myDog);
// Any changes made to myDog must have occured in the constructor, but
// we haven't even displayed the dialog yet!
properyDialog.S howDialog;
I understand that this isn't the correct way of doing this, as the
constructor doesn't modify myDog, so passing a ref is a waste of time.
What I'm wondering is, how do other people go about achieving this
task?
I'm guessing that you would derive the Dog class form a Windows.Form
class, with a method of this class used to display the form element? If
so, would it be good practise to make this method static (only one
properties dialog can be open at a time anyway)?
As I said earlier, I'm fairly new to c#, so please excuse me if I'm
missing the obvious.
'properties' dialog works.
Currently in my code, I have an object represented by the class 'Dog'.
The dog object has several properties.
I have added a new windows form, class 'DogProperties' . I'm attempting
to use this to allow the user to edit the properties of an instance of
'Dog'.
To do this, I'm passing an instance of 'Dog' as a ref parameter to the
constructor of 'DogProperties' . The problem is, updated properties can
not be sent back, as the ref is only valid for the constructor.
An example of the existing code I have would be
// Create an instance of our properties dialog
DogProperties propertyDialog = new DogProperties(r ef myDog);
// Any changes made to myDog must have occured in the constructor, but
// we haven't even displayed the dialog yet!
properyDialog.S howDialog;
I understand that this isn't the correct way of doing this, as the
constructor doesn't modify myDog, so passing a ref is a waste of time.
What I'm wondering is, how do other people go about achieving this
task?
I'm guessing that you would derive the Dog class form a Windows.Form
class, with a method of this class used to display the form element? If
so, would it be good practise to make this method static (only one
properties dialog can be open at a time anyway)?
As I said earlier, I'm fairly new to c#, so please excuse me if I'm
missing the obvious.
Comment