c# - Access Form Method from another static class -
so, i'm pretty out of clues now, not sure if it's possible after all. have visual c# form, gets run program.cs (standard way - vs did setup work of course).
in addition that, have class static method in seperate c# file, because keeping 1 class in 1 file.
my form code has public function:
public void print(string text) { rtb_log.appendtext("\n" + text); }
at point of time, i'm calling static function other class.
is possible, access print method other class? since it's referring rtb_log ( rich text box), it's availible if instanced, , of course not static. since static methods can access static members, i'm little out of ideas here on how append text on form class.
any here?
but since static methods can access static members, i'm little out of ideas here on how append text on form class.
static members can access instance members - need know instance call method on. write:
public static void foo(otherform myotherform) { // stuff... myotherform.print(); // case changed comply naming conventions }
then when call method, need supply reference relevant form. something has determine instance want call print
on. work out has information, , pass on there. recommend against using static variable hold information. (global state makes code less reusable, harder reason about, , harder test.)
edit: given comments, sounds want:
// within form private void handleclick(object sender, eventargs e) { someclass.staticmethod(this); }
Comments
Post a Comment