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. problem with move values between two running forms

problem with move values between two running forms

Scheduled Pinned Locked Moved C#
help
12 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.
  • C Christian Graus

    Mr.Kode wrote:

    Form1 F1 = (Form1 )this.Owner; F1.textbox1.text = label1.Text; // i had set textbox1 modifier property to public

    This should work, although it's probably the nastiest code I've seen today ( and that's huge ). 1 - why on earth can't anyone here give their variables meaningful names ? Form1 ? Label1 ? Are you all REALLY comfortable with that ? 2 - making your controls public is retarded. If you must, make a string property public that sets the text on the label, but don't expose the whole thing. If your doctor asks to see the back of your knee, do you take all your clothes off ? 3 - you say 'I have troubles' then you post code that looks like it should work. What troubles ? What's happening ? Does it run ? Does it blow up ? If you want to ask a question, you need to be CLEAR 4 - the best way to communicate between forms is delegates. Then no properties need to be exposed.

    Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

    D Offline
    D Offline
    dan sh
    wrote on last edited by
    #3

    Christian Graus wrote:

    If your doctor asks to see the back of your knee, do you take all your clothes off ?

    Depends on the doctor.

    It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD

    C 1 Reply Last reply
    0
    • D dan sh

      Christian Graus wrote:

      If your doctor asks to see the back of your knee, do you take all your clothes off ?

      Depends on the doctor.

      It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #4

      Good call.

      Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

      1 Reply Last reply
      0
      • C Christian Graus

        Mr.Kode wrote:

        Form1 F1 = (Form1 )this.Owner; F1.textbox1.text = label1.Text; // i had set textbox1 modifier property to public

        This should work, although it's probably the nastiest code I've seen today ( and that's huge ). 1 - why on earth can't anyone here give their variables meaningful names ? Form1 ? Label1 ? Are you all REALLY comfortable with that ? 2 - making your controls public is retarded. If you must, make a string property public that sets the text on the label, but don't expose the whole thing. If your doctor asks to see the back of your knee, do you take all your clothes off ? 3 - you say 'I have troubles' then you post code that looks like it should work. What troubles ? What's happening ? Does it run ? Does it blow up ? If you want to ask a question, you need to be CLEAR 4 - the best way to communicate between forms is delegates. Then no properties need to be exposed.

        Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

        M Offline
        M Offline
        Mr Kode
        wrote on last edited by
        #5

        thanks Christian .. but i am still suffering error null reference exception was unhandled

        C 1 Reply Last reply
        0
        • M Mr Kode

          thanks Christian .. but i am still suffering error null reference exception was unhandled

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #6

          What line gives you the error ? Did you change your code completely to get rid of all the stuff I said was retarded and use delegates ?

          Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

          M 1 Reply Last reply
          0
          • C Christian Graus

            What line gives you the error ? Did you change your code completely to get rid of all the stuff I said was retarded and use delegates ?

            Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

            M Offline
            M Offline
            Mr Kode
            wrote on last edited by
            #7

            F1.textbox1.text = label1.Text; the exception fires on that line i`ll try to delegate that ,but for now i need to solve the problem

            C 1 Reply Last reply
            0
            • M Mr Kode

              F1.textbox1.text = label1.Text; the exception fires on that line i`ll try to delegate that ,but for now i need to solve the problem

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #8

              Well, it would help if you knew what you were doing. I assume you have no idea what object is null ? Do you have any idea how to use the debugger ? Hit F9 with the focus on this line to set a breakpoint, hit F5 to debug and when the code stops on this line, you can hover over each object. Either F1 is null ( which seems unlikely as you cast it and don't use 'as' ), label1 is null ( unlikely as it's a local object ) or textbox1 is null. Once you work out which is null, you can work out why. Do you set the Owner of the form when you create it ? That may be the problem.

              Mr.Kode wrote:

              but for now i need to solve the problem

              Why ? This is surely not code that someone is going to use in real life ? It's a disaster, as I said.

              Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

              M 1 Reply Last reply
              0
              • C Christian Graus

                Well, it would help if you knew what you were doing. I assume you have no idea what object is null ? Do you have any idea how to use the debugger ? Hit F9 with the focus on this line to set a breakpoint, hit F5 to debug and when the code stops on this line, you can hover over each object. Either F1 is null ( which seems unlikely as you cast it and don't use 'as' ), label1 is null ( unlikely as it's a local object ) or textbox1 is null. Once you work out which is null, you can work out why. Do you set the Owner of the form when you create it ? That may be the problem.

                Mr.Kode wrote:

                but for now i need to solve the problem

                Why ? This is surely not code that someone is going to use in real life ? It's a disaster, as I said.

                Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

                M Offline
                M Offline
                Mr Kode
                wrote on last edited by
                #9

                thanks Christian i found where the error is i forget that f1 have mdiparent to another form but i want to know why i can`t set mdiparent and owner at the same time?

                C 1 Reply Last reply
                0
                • M Mr Kode

                  thanks Christian i found where the error is i forget that f1 have mdiparent to another form but i want to know why i can`t set mdiparent and owner at the same time?

                  C Offline
                  C Offline
                  Christian Graus
                  wrote on last edited by
                  #10

                  Because the owner exists entirely to create a relationship in terms of how the form is shown, and it's invalid if it's got an MDIparent instead.

                  Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

                  1 Reply Last reply
                  0
                  • M Mr Kode

                    hello all i have troubles with the following code there are two forms Form1 and Form2 Form1 is the owner of Form2 i need to move label1.text from Form2 to Form1 (note: both forms are running and visible) here is my code Form1 F1 = (Form1 )this.Owner; F1.textbox1.text = label1.Text; // i had set textbox1 modifier property to public thanks in advance

                    A Offline
                    A Offline
                    AhmedMasum
                    wrote on last edited by
                    #11

                    where you wrote this code?? under form1 or under form2? what you really want do?please describe in details...

                    1 Reply Last reply
                    0
                    • M Mr Kode

                      hello all i have troubles with the following code there are two forms Form1 and Form2 Form1 is the owner of Form2 i need to move label1.text from Form2 to Form1 (note: both forms are running and visible) here is my code Form1 F1 = (Form1 )this.Owner; F1.textbox1.text = label1.Text; // i had set textbox1 modifier property to public thanks in advance

                      H Offline
                      H Offline
                      hosseinghazanfary
                      wrote on last edited by
                      #12

                      dude i think ur trying to move a string(lable1.text) from form1 to form2,it's easy. for example u want have a button,when clicked u want to show second form. form2 f2=new form2(); ok,now goto ur form2.cs code view,in the first lines u c something like this: public form2() { initializecomponent(); } now change the arguments that form2 needs,in the code above,u c that second form doesn need anything for being instanced,change it like this: public form2(string labltext) { ... } now when u want to make an instance of the second form,pass the string in that way: form2 f2=new form2(label1.text) in second form u can access the string throw variable labltext. have fun :rose:

                      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