Calling Method in Form1 from Form2
-
Hi, Using Visual Studio 2003. I'm calling a method located in Form1 from Form2. I'm doing it by creating an object of Form1 Form1 myForm1 = new Form1(); myForm1.MethodToCall(); I originally made the method static (to call on it), but this method calls on another method and variables, so it seemed easier to create an object in Form2. The problem I'm having is: In the method I'm calling, I have code to change the text of a label control. The label text is not changing and it looks like I need to declare the label as "static"... is this correct? If so, is it possible to set this (label to static) in Visual Studio Properties Window, or do I need to create the label code myself in order to use static on a label? thanks, Ron
-
Hi, Using Visual Studio 2003. I'm calling a method located in Form1 from Form2. I'm doing it by creating an object of Form1 Form1 myForm1 = new Form1(); myForm1.MethodToCall(); I originally made the method static (to call on it), but this method calls on another method and variables, so it seemed easier to create an object in Form2. The problem I'm having is: In the method I'm calling, I have code to change the text of a label control. The label text is not changing and it looks like I need to declare the label as "static"... is this correct? If so, is it possible to set this (label to static) in Visual Studio Properties Window, or do I need to create the label code myself in order to use static on a label? thanks, Ron
-
Hi, Using Visual Studio 2003. I'm calling a method located in Form1 from Form2. I'm doing it by creating an object of Form1 Form1 myForm1 = new Form1(); myForm1.MethodToCall(); I originally made the method static (to call on it), but this method calls on another method and variables, so it seemed easier to create an object in Form2. The problem I'm having is: In the method I'm calling, I have code to change the text of a label control. The label text is not changing and it looks like I need to declare the label as "static"... is this correct? If so, is it possible to set this (label to static) in Visual Studio Properties Window, or do I need to create the label code myself in order to use static on a label? thanks, Ron
-
Hi rahul, The label I want to change is on Form1. Setting the label to public did not help. Ron
-
there doesn't seem any problem in ur code. just try to set the label as public.
sAqIb "Our scientific power has outrun our spiritual power. We have guided missiles and misguided men." Dr. Martin Luther King Jr.
Hi sAqib, Yes, the label is set to public. Could the problem be that label properties are placed in the constructor by default? It only seems to work if "static" is used and the label properties are set in the FormLoad event. What you think? Ron