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. use control in other form

use control in other form

Scheduled Pinned Locked Moved C#
question
7 Posts 4 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.
  • N Offline
    N Offline
    NiloofarNoroozi
    wrote on last edited by
    #1

    how can i use txtNoPersoneli when this is in other form?

    D N N 3 Replies Last reply
    0
    • N NiloofarNoroozi

      how can i use txtNoPersoneli when this is in other form?

      D Offline
      D Offline
      DaveyM69
      wrote on last edited by
      #2

      If txtNoPersoneli's access modifier is public then you should be able to access it through otherforminstance.txtNoPersoneli Better still, create events in otherform that are rasied when whatever your interested in with txtNoPersoneli occurs, and subscribe to these in the initial form.

      Dave
      BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
      Expect everything to be hard and then enjoy the things that come easy. (code-frog)

      N 1 Reply Last reply
      0
      • N NiloofarNoroozi

        how can i use txtNoPersoneli when this is in other form?

        N Offline
        N Offline
        N a v a n e e t h
        wrote on last edited by
        #3

        You change the access modifier to public, but it is not recommended as it breaks OO rules. Use delegates to communicate between forms. CP has an article on this subject.

        All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

        1 Reply Last reply
        0
        • D DaveyM69

          If txtNoPersoneli's access modifier is public then you should be able to access it through otherforminstance.txtNoPersoneli Better still, create events in otherform that are rasied when whatever your interested in with txtNoPersoneli occurs, and subscribe to these in the initial form.

          Dave
          BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
          Expect everything to be hard and then enjoy the things that come easy. (code-frog)

          N Offline
          N Offline
          NiloofarNoroozi
          wrote on last edited by
          #4

          i change to public,but yet i can not use that

          D 1 Reply Last reply
          0
          • N NiloofarNoroozi

            i change to public,but yet i can not use that

            D Offline
            D Offline
            DaveyM69
            wrote on last edited by
            #5

            You have to access it through an instance of the second form. For example, if the form is called Form2 then:

            Form2 form2 = new Form2();
            // any other stuff here
            form2.txtNoPersoneli.Text = "Text";

            Dave
            BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
            Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)

            D 1 Reply Last reply
            0
            • N NiloofarNoroozi

              how can i use txtNoPersoneli when this is in other form?

              N Offline
              N Offline
              nelsonpaixao
              wrote on last edited by
              #6

              listen, you have to use delegates, search: transfer data between form here in codeproject. you may want to drop the idea of using more than 1 form :( use parentform/childform method or 1form + 10usercontrols (usercontrols that load in form like page, i use it a lot) method i use delegates, see the following exemple (here i trigger a text msg FROM usercontrol IN form): in userform

              public delegate void Delegate_TransferPageInfo(string msg);
              public event Delegate_TransferPageInfo Event_TransferPageInfo;

              private void ToolStripButton_Add_Click(object sender, EventArgs e)
              {...
              Event_DriverPageInfo("ERROR: invalid birth date");//trigger
              ...}

              in form

              private void Form_Main_Load(object sender, EventArgs e)
              {...
              UserControl_DriverPage_Child.Event_DriverPageInfo += new UserControl_DriverPage.Delegate_DriverPageInfo(Page_Info);
              ...}
              protected void Page_Info(string msg)
              {
              ToolStripStatusLabel_MainInfo.Text = msg;
              }

              can´t help you more!!! ;P

              nelsonpaixao@yahoo.com.br trying to help & get help

              1 Reply Last reply
              0
              • D DaveyM69

                You have to access it through an instance of the second form. For example, if the form is called Form2 then:

                Form2 form2 = new Form2();
                // any other stuff here
                form2.txtNoPersoneli.Text = "Text";

                Dave
                BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
                Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)

                D Offline
                D Offline
                DaveyM69
                wrote on last edited by
                #7

                Whoever univoted this - I agree that it's not best practice and if you look at my previous reply I did suggest using events (implies delegates too). The question in response to that from the OP was specifically on the unrecommended way, to which I gave an accurate and working response! X| ;P

                Dave
                BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
                Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)

                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