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. text changed on another form

text changed on another form

Scheduled Pinned Locked Moved C#
question
8 Posts 5 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.
  • U Offline
    U Offline
    User 589870
    wrote on last edited by
    #1

    hi, i have two forms and i m changing text of a control on second form from first form through a static property.now i show the second form but the text doesnt changes.wat is wrong?

    N C OriginalGriffO S 4 Replies Last reply
    0
    • U User 589870

      hi, i have two forms and i m changing text of a control on second form from first form through a static property.now i show the second form but the text doesnt changes.wat is wrong?

      N Offline
      N Offline
      nagendrathecoder
      wrote on last edited by
      #2

      Can you show your code? Its difficult to tell what is wrong without seeing your code.

      1 Reply Last reply
      0
      • U User 589870

        hi, i have two forms and i m changing text of a control on second form from first form through a static property.now i show the second form but the text doesnt changes.wat is wrong?

        C Offline
        C Offline
        Calla
        wrote on last edited by
        #3

        Post code or elaborate your question (preferably the first one :)).

        1 Reply Last reply
        0
        • U User 589870

          hi, i have two forms and i m changing text of a control on second form from first form through a static property.now i show the second form but the text doesnt changes.wat is wrong?

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          There could be so many things wrong, it is impossible to be definite. However, the first question for you is: why are you using a static property? You do realise that it is shared by all instances of the form? Try using a public property on Form2, and use it in the form load event:

          public string myText { get; set; }
          ...
          private void Form2_Load(object sender, EventArgs e)
          {
          label1.Text = myText;
          }

          Then in Form1:

          Form2 myForm = new Form2();
          myForm.myText = "Hello World!";
          myForm.Show();

          If this doesn't solve your problem, then you will have to post relevent code fragments from Form1 and Form2 (enclosing in <pre>...</pre> blocks with the "code block" widget to preserve the formatting and make it easier to read) - don't just post your entire project, nobody wants to wade through loads of irrelevant code!

          You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          U 1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff

            There could be so many things wrong, it is impossible to be definite. However, the first question for you is: why are you using a static property? You do realise that it is shared by all instances of the form? Try using a public property on Form2, and use it in the form load event:

            public string myText { get; set; }
            ...
            private void Form2_Load(object sender, EventArgs e)
            {
            label1.Text = myText;
            }

            Then in Form1:

            Form2 myForm = new Form2();
            myForm.myText = "Hello World!";
            myForm.Show();

            If this doesn't solve your problem, then you will have to post relevent code fragments from Form1 and Form2 (enclosing in <pre>...</pre> blocks with the "code block" widget to preserve the formatting and make it easier to read) - don't just post your entire project, nobody wants to wade through loads of irrelevant code!

            You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy

            U Offline
            U Offline
            User 589870
            wrote on last edited by
            #5

            thanx all problem solved...

            U 1 Reply Last reply
            0
            • U User 589870

              thanx all problem solved...

              U Offline
              U Offline
              User 589870
              wrote on last edited by
              #6

              actually the form2 was getting disposed before setting its control's text...

              OriginalGriffO 1 Reply Last reply
              0
              • U User 589870

                hi, i have two forms and i m changing text of a control on second form from first form through a static property.now i show the second form but the text doesnt changes.wat is wrong?

                S Offline
                S Offline
                sanforjackass
                wrote on last edited by
                #7

                you can use delegation to solve your problem

                EASY COME EASY GO

                1 Reply Last reply
                0
                • U User 589870

                  actually the form2 was getting disposed before setting its control's text...

                  OriginalGriffO Offline
                  OriginalGriffO Offline
                  OriginalGriff
                  wrote on last edited by
                  #8

                  Oops. :doh:

                  You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy

                  "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                  "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                  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