Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. how to access to Control's Property from other forms ?

how to access to Control's Property from other forms ?

Scheduled Pinned Locked Moved C#
tutorialquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hdv212
    wrote on last edited by
    #1

    hi i want to access Form1.textbox1.Text and change it from Form2 ,How to do that ???

    P 1 Reply Last reply
    0
    • H hdv212

      hi i want to access Form1.textbox1.Text and change it from Form2 ,How to do that ???

      P Offline
      P Offline
      PicklesTheClown
      wrote on last edited by
      #2

      Form2 needs access to textBox1. There are various ways you can accomplish this. One might be...

      public class Form2 : Form
      { 
         private TextBox _textBox;
         public TextBox RemoteTextBox
         {  get{ _textBox = value; } }
         // ...
      }
      
      form2.RemoteTextBox = form1.textBox1;
      
      H 1 Reply Last reply
      0
      • P PicklesTheClown

        Form2 needs access to textBox1. There are various ways you can accomplish this. One might be...

        public class Form2 : Form
        { 
           private TextBox _textBox;
           public TextBox RemoteTextBox
           {  get{ _textBox = value; } }
           // ...
        }
        
        form2.RemoteTextBox = form1.textBox1;
        
        H Offline
        H Offline
        hdv212
        wrote on last edited by
        #3

        hi and thanks can you show me other ways for solve this problem ??? regards ...

        D 1 Reply Last reply
        0
        • H hdv212

          hi and thanks can you show me other ways for solve this problem ??? regards ...

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          This is actually bad OOP practice. Form2 would be forever linked and totally dependant on the existance of Form1. Form2 should never care about Form1 at all. Each form is responsible for the manipulation of the controls on it, not other forms. If you need to do something on Form1, expose an event on Form2 that Form1 subscribes to. This way, other forms can subscribe to that event and do whatever they need to do in response to that event. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups