c# - Accessing UserControl Methods and properties from other Class -


what have user control contains combobox , datagrid , trying accessing usercontorl methods within other class named class1 , in class 1 have methods take advantage of method in usercontrol(since user control contains necessary data combobox.tex)

//the user control code      public partial class usercontrol1 : usercontrol     {         public usercontrol1()         {           initializecomponent();           }        public string mymethod()        {        return combobox.text ;        }     }  // other class  class class1 { //here want access method withen of usercontrol class usercontrol1 cnt= new usercontrol1() //also tried var cnt= new usercontrol1() cnt.mymethod()  } 

what have been trying create instance of usercontorl in class1 no result since new instance . @ point have created property inside usercontrol class pass neccesary data no luck .

you expose form class1 passing parameter constructor:

class class1 {     private readonly usercontrol _usercontrol;      public class1(usercontrol usercontrol)     {         _usercontrol = usercontrol;     }      public void somemethod()     {         _usercontrol.mymethod() etc     } } 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -