How to use controls of one class in another class in c#.net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • neehakale
    New Member
    • Aug 2007
    • 46

    How to use controls of one class in another class in c#.net

    I have one text box button, say by name txtmessage in one form (MainForm )and what i have to do is on click of OK buttton in the other form (SubForm) I have to write some message in that txtmessage text box....please help me to do this
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    Here is an article that may help:
    Coding a 'One-to-Many' Form with ASP.NET

    Comment

    • Munawar
      New Member
      • May 2007
      • 12

      #3
      hi, if you have windows applicationt then you can do that as following:
      lets suppose on form1 you have a button and on form2 has textbox

      you can make textbox public on form2 and then in form1 create instance of form2 and set the value of textbox

      in button click event write the following..
      Form2 f=new Form2()
      Form2.TextBox1. Text="hello"
      this.close()

      further you can create a public property on form2 and set the value from any other form

      Code:
       public string UserID
              {
                  set
                  {
                      this.textBox1.Text = value ;
                  }
                  get
                  {
                      return UserID ;
                  }
              }
      thanks,
      Munawar

      Comment

      Working...