Hi,
I wasn't sure the best place to post this, so feel free to move it to the appropriate place.
Anyway, I'm new to VB.NET an OOP and I was having a problem with an application I am writing that runs in the task tray using the Notify Icon component.
I created a class that I am using to handle application configuration data. This class is small and has the following properties and methods. I also want to make this class serializable, except the IsDirty flag. I realize I may need to write custom code to serialize eveything but this property.
Properties:
int RefreshDuration
string URL
string ExcludeList
Methods:
void LoadSettings
void SaveSettings
bool IsDirty
In my main form I created an instance of the Settings class and I can set the various properties and call the various methods without any problems. I am have problems when I want to access components on my main form from this class and I am not sure if this is the best way to do it since the Settings class will need to be changed if I ever want to use it in another project.
Here's what I am wanting to happen:
1. LoadSettings is called on application startup.
2. The user changes any setting and I want to set the IsDirty property to true, which in turn enables the Ok button on the settings form.
2.1 If the user clicks Ok, then I want to call SaveSettings, set IsDirty to false, which disables the Ok button.
2.2 The user closes the form and get prompted to Save changes, with Yes/No/Cancel message box.
2.2.1 If the user clicks Yes, then I want to do 2.1
2.2.2 If the user clicks No, then want to set IsDirty to false, which disables the Ok button.
2.2.3 The message box closes and the settings form remains and IsDirty still = false.
However, when I try to code step 2, then I can't seem to access the main form controls, such as the Ok button, to enable/disable it. Somehow the IsDirty property doesn't seem like the best place to enable/disable the button anyway.
I have attached a small sample project and if anyone could help explain the best way to create a reusable settings class I would appreciate it.
Also, I don't mind using a true application config file for my settings, but just to understand how I would accomplish the above would be great.
Thanks,
CT
I wasn't sure the best place to post this, so feel free to move it to the appropriate place.
Anyway, I'm new to VB.NET an OOP and I was having a problem with an application I am writing that runs in the task tray using the Notify Icon component.
I created a class that I am using to handle application configuration data. This class is small and has the following properties and methods. I also want to make this class serializable, except the IsDirty flag. I realize I may need to write custom code to serialize eveything but this property.
Properties:
int RefreshDuration
string URL
string ExcludeList
Methods:
void LoadSettings
void SaveSettings
bool IsDirty
In my main form I created an instance of the Settings class and I can set the various properties and call the various methods without any problems. I am have problems when I want to access components on my main form from this class and I am not sure if this is the best way to do it since the Settings class will need to be changed if I ever want to use it in another project.
Here's what I am wanting to happen:
1. LoadSettings is called on application startup.
2. The user changes any setting and I want to set the IsDirty property to true, which in turn enables the Ok button on the settings form.
2.1 If the user clicks Ok, then I want to call SaveSettings, set IsDirty to false, which disables the Ok button.
2.2 The user closes the form and get prompted to Save changes, with Yes/No/Cancel message box.
2.2.1 If the user clicks Yes, then I want to do 2.1
2.2.2 If the user clicks No, then want to set IsDirty to false, which disables the Ok button.
2.2.3 The message box closes and the settings form remains and IsDirty still = false.
However, when I try to code step 2, then I can't seem to access the main form controls, such as the Ok button, to enable/disable it. Somehow the IsDirty property doesn't seem like the best place to enable/disable the button anyway.
I have attached a small sample project and if anyone could help explain the best way to create a reusable settings class I would appreciate it.
Also, I don't mind using a true application config file for my settings, but just to understand how I would accomplish the above would be great.
Thanks,
CT
Attachments
Last edited: