Initiating a process from child
-
Hi everyone, I just recently started programming in C# (my first language, also) and I'm still pretty green. I was wondering how, or if it's possible, to initiate a process in a parent form when a boolean variable in it's child form is set to "true". I see events such as "text changed" but I need something in the parent that can catch a variable change on the child as soon as it occurs and take action right away. Any suggestions? Thanks! :)
-
Hi everyone, I just recently started programming in C# (my first language, also) and I'm still pretty green. I was wondering how, or if it's possible, to initiate a process in a parent form when a boolean variable in it's child form is set to "true". I see events such as "text changed" but I need something in the parent that can catch a variable change on the child as soon as it occurs and take action right away. Any suggestions? Thanks! :)
-
you could try creating your own events in the child class and handling them in the parent class. look here for good example: http://www.ondotnet.com/pub/a/dotnet/2002/04/15/events.html[^]
-
I dont think you can take another approach. If you want to do something, when another form changes you need to listen for that change. I dont know what your exact requirements are but perhaps you could use static functions in another class. Or just call the function by accessing the child forms parent form. something like (though i have not tested):
FormOfTypeParent parentForm = (FormOfTypeParent)this.ParentForm;
parentForm.MyFunction();FormOfTypeParent = the form type that is your parent form i.e. MainForm, Form1 etc. calling this when a variable changes, make the variable a property i.e.
private bool changingThing = false;
public bool ChangingThing{
get{return changingThing;}
set{changingThing = value;ProcessChange();}
}private void ProcessChange()
{
if(changingThing)
{
FormOfTypeParent parentForm = (FormOfTypeParent)this.ParentForm;
parentForm.MyFunction();
}
} -
Hi everyone, I just recently started programming in C# (my first language, also) and I'm still pretty green. I was wondering how, or if it's possible, to initiate a process in a parent form when a boolean variable in it's child form is set to "true". I see events such as "text changed" but I need something in the parent that can catch a variable change on the child as soon as it occurs and take action right away. Any suggestions? Thanks! :)
I am attempting to find another way to get around this problem, so I have another question regarding this: Is it possible to call an event in a child form from the parent form? I've attempted this in the past without success, but I feel that it should be possible given that events that don't involve "physical" (such as a button click event) components on the form can be called by the parent. Can anyone verify this and/or explain why/how it is or is not possible? Thanks so much!