c# - How do I call a method that only accepts a parameter that is in another form? -
i have form1 (that runs program) , form2 (that form user input). form2 has function clears user input (textboxes, checkboxes, combo boxes, clears them).
the function looks this:
public void cleartheform(control groupofcontrols) { foreach (control c in groupofcontrols.controls) { if (c textbox) { ((textbox)c).clear(); } if (c.haschildren) { cleartheform(c); } if (c checkbox) { ((checkbox)c).checked = false; } label3.text = ""; combobox1.selectedindex = -1; combobox2.selectedindex = -1; } } this works on own. on main form, need call function, should this:
i make instance of form2 call inputform , then:
private void addrecord_click(object sender, eventargs e) { inputform.showdialog(); if(inputform.addedrecord == true) { inputform.addrecord(); inputform.cleartheform(what put in here??); } } so once record has been added, input form clears , ready record added.
the question above, put in there? how call groupofcontrols in inputform.cleartheform() located in form2 form1?? tried make public control groupofcontrols on top of form2 , leave form1 inputform.cleartheform(control groupofcontorls), saids don't have object reference. if leave blank saids inputform.cleartheform(); not take 0 arguement.
well, if wanted clear all controls in inputform write version of cleartheform() without parameter, , call version with parameter it, so:
public void cleartheform() { cleartheform(this); // passes controls in form. } or can call original cleartheform(control) passing reference inputform argument: inputform.cleartheform(inputform).
if want clear controls, i'd write separate parameterless method clarity.
however, useful if want clear controls in inputform.
Comments
Post a Comment