problem with move values between two running forms
-
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.
-
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
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.
-
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.
-
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.
-
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.
-
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
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.
-
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.
-
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?
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.
-
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
where you wrote this code?? under form1 or under form2? what you really want do?please describe in details...
-
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
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: