c# - Accessing properties of Form elements in another class -


i have window form textboxes,checkboxes,comboboxes , buttons.i have separate class updates data in database using values of orignal winform elements.i want access properties(text,checked etc) of or of feilds of form elements in class.the problem is-

1.if use parameterised function call parameters list become too large. eg-function(int a,bool c,string d,int e,int f,bool e,bool h,string g) working looks untidy , don't know whether programming methodology.

2.i can use static variables have create separate function updates static variable's value. index change in combobox.(but people avoid static..)

3.also dont want use instance objects of main form class have create object of original form class repeatedly @ many places.(which resource expensive).. question technique use on account of programming methods???or there better way it...

1) can group parameters class or struct , pass instance function updates gui control.

2) don't use static variables - you'd make arguments global not want do.

3) not creating new instance of myform class if you're passing , using reference in db client class:

// class data want use update gui controls class mydata {    public string text1 { get; set; }    public string text2 { get; set; }    ... }  // class obtains data db class dbclient {    myform myform;     dbclient(myform myform)    {        this.myform = myform; // you're passing reference myform here, you're not creating new object    }     void updateformcontrols()    {        mydata data = ...; // fill data obtained from db         myform.updatecontrols(data);    } }  // custom form containing various controls class myform : form {    dbclient dbclient;     myform()    {       dbclient = new dbclient(this);    }     public void updatecontrols(mydata data)    {       if (invokerequired)       {          this.begininvoke((methodinvoker) delegate { updatecontrols(data); });          return;       }        control1.text = data.text1;       control2.text = data.text2;       ...    }    } 

even better if decouple dbclient , myform making myform implement interface , using interface reference in dbclient class.


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -