use of information from a previous form
-
let us consider we have two forms form1 and form2 and there are some information in form1 that i would like to use in form2... which method should i use to perform this action?
-
let us consider we have two forms form1 and form2 and there are some information in form1 that i would like to use in form2... which method should i use to perform this action?
if form1 create form2 then from form2 you can define a public var. like this: int x; public int X { set { x=value; } } then when you create you can send the var. like this: form2 f2=new form2(); f2.X=5; f2.show();
-
if form1 create form2 then from form2 you can define a public var. like this: int x; public int X { set { x=value; } } then when you create you can send the var. like this: form2 f2=new form2(); f2.X=5; f2.show();
suppose we have a tab of buttons in form1 and i want to use the text of the clicked button in form2... how can i do such a thing?
-
let us consider we have two forms form1 and form2 and there are some information in form1 that i would like to use in form2... which method should i use to perform this action?
There are three obvious ways if
Form1
is the parent. 1.Form1
sets a property inForm2
(as suggested above) 2.Form1
calls a method inForm2
3.Form2
raises a customDataRequest
event with customEventArgs
.Form1
subscribes to this and fills the event args accordingly when it handles the event. IfForm2
is the parent form then aDataChanged
event inForm1
and a suitable handler inForm2
is the way to go. If the hierachy is different, then a combination of the above up and down the hierachy will work. If that gets too complex then a separate manager class that routes events between the class instances can be useful.Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Why are you using VB6? Do you hate yourself? (Christian Graus) -
suppose we have a tab of buttons in form1 and i want to use the text of the clicked button in form2... how can i do such a thing?
use delegation: in form1 create textbox and put: public delegate void dd(string s); public static dd d; and put (d=new dd(write);) in public Form1() then write method (write): privet void write(string s) { textbox1.text=s; } in form2 create button and textbox then in click event put: Form1.d(textbox1);
modified on Wednesday, January 20, 2010 6:53 PM