FYP Final Report v1.0.0
Copyright and All Rights Reserved To: Pee-Lo Team @2003/04
49
4.3.1.2 Implementation Challenges
1. userControl calling another userControl
Because the forms are putting together with UserControls, I have hard times to figure out
how to make it, by clicking a button on one userControl, will call out another
userControl. As an example, from Appendix D: Screenshot 6, clicking Patient button at
UserControlNav (Title: Explorer Bar) will call out the UserControlPatient (Title:
Patient).
I solved it by creating a btnNavPatient_Click() function at
UserControlPatient.cs. It will first check the current loading form using
validateMDIChild()
. Assume that now we are using frmAdmin (Title: Administrator), the
validateMDIChild()
will return true and proceed passing the control to frmAdmin by using
fAdCorrect.userCtrlClick_ShowPatient();
// UserControlPatient.cs
private void btnNavPatient_Click(object sender, System.EventArgs e)
{
if(validateMDIChild() == true)
{
frmAdmin fAdCorrect = (frmAdmin)this.FindForm();
fAdCorrect.userCtrlClick_ShowPatient();
txtLoginName.Text = fAdCorrect.passLoginNameToUserCtrl();
}
else
{
frmPhysician fPhyCorrect = (frmPhysician)this.FindForm();
fPhyCorrect.userCtrlClick_ShowPatient();
txtLoginName.Text = fPhyCorrect.passLoginNameToUserCtrl();
}
}
Snippet 11: userControl Calling Another userControl (1)
Now, the frmAdmin will be called to invoke the click event of the ShowPatient Menu Item
miShowPatient.PerformClick();
and then will invoke the ShowPatient(object
sender, System.EventArgs e)
function. That is how I solved the problem. The whole idea
is, because both of the userContols are attached to one specific form, what I can do is to
make the particular form act as the intermediate between them. UserControlNav (Title:
Explorer Bar) let frmAdmin (Title: Administrator) call out the UserControlPatient (Title:
Patient).
// frmAdmin.cs
public void userCtrlClick_ShowPatient()
{
miShowPatient.PerformClick();
hide_panelLoginInfo();
}