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. Calling Method in Form1 from Form2

Calling Method in Form1 from Form2

Scheduled Pinned Locked Moved C#
csharpvisual-studiohelpquestion
5 Posts 3 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.
  • M Offline
    M Offline
    myNameIsRon
    wrote on last edited by
    #1

    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

    R S 2 Replies Last reply
    0
    • M myNameIsRon

      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

      R Offline
      R Offline
      rah_sin
      wrote on last edited by
      #2

      label control is on which form?

      rahul

      M 1 Reply Last reply
      0
      • M myNameIsRon

        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

        S Offline
        S Offline
        saqib82
        wrote on last edited by
        #3

        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.

        M 1 Reply Last reply
        0
        • R rah_sin

          label control is on which form?

          rahul

          M Offline
          M Offline
          myNameIsRon
          wrote on last edited by
          #4

          Hi rahul, The label I want to change is on Form1. Setting the label to public did not help. Ron

          1 Reply Last reply
          0
          • S saqib82

            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.

            M Offline
            M Offline
            myNameIsRon
            wrote on last edited by
            #5

            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

            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