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. "How can I call a function from another form"

"How can I call a function from another form"

Scheduled Pinned Locked Moved C#
questioncsharpwinformshelptutorial
5 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.
  • O Offline
    O Offline
    Orchid85
    wrote on last edited by
    #1

    Dear every one, I am new in C# and I have a question about call function between two windows forms. In my project I have two windows form (form example Form1 and Form2) Form1 has some functions for itself(for example Func1,Func2,..) and Form2 has another functions (for example TempFunc1,TempFunc2,..).I'd like to call Func1 via Form2,I mean when the program is running and the TempFunc1 from Form2 is doing I want to call Func1 from Form1,how can I do this? Please help me. Yours Sincerely. Orchid

    C N C 3 Replies Last reply
    0
    • O Orchid85

      Dear every one, I am new in C# and I have a question about call function between two windows forms. In my project I have two windows form (form example Form1 and Form2) Form1 has some functions for itself(for example Func1,Func2,..) and Form2 has another functions (for example TempFunc1,TempFunc2,..).I'd like to call Func1 via Form2,I mean when the program is running and the TempFunc1 from Form2 is doing I want to call Func1 from Form1,how can I do this? Please help me. Yours Sincerely. Orchid

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

      The main way to do this is to create delegates, so that your forms can call functions within each other. If you want something more quick and dirty, pass an instance of each form to the other form, and make the methods public. We need a FAQ, and this needs to be the first item on it. In fact, I thought we had one ?

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

      N 1 Reply Last reply
      0
      • O Orchid85

        Dear every one, I am new in C# and I have a question about call function between two windows forms. In my project I have two windows form (form example Form1 and Form2) Form1 has some functions for itself(for example Func1,Func2,..) and Form2 has another functions (for example TempFunc1,TempFunc2,..).I'd like to call Func1 via Form2,I mean when the program is running and the TempFunc1 from Form2 is doing I want to call Func1 from Form1,how can I do this? Please help me. Yours Sincerely. Orchid

        N Offline
        N Offline
        Nafiseh Salmani
        wrote on last edited by
        #3

        you could use of this function such as using a function in a class . Create a new instanse of ur form class and then call your function

        1 Reply Last reply
        0
        • O Orchid85

          Dear every one, I am new in C# and I have a question about call function between two windows forms. In my project I have two windows form (form example Form1 and Form2) Form1 has some functions for itself(for example Func1,Func2,..) and Form2 has another functions (for example TempFunc1,TempFunc2,..).I'd like to call Func1 via Form2,I mean when the program is running and the TempFunc1 from Form2 is doing I want to call Func1 from Form1,how can I do this? Please help me. Yours Sincerely. Orchid

          C Offline
          C Offline
          Colin Angus Mackay
          wrote on last edited by
          #4

          See this article: Passing values between Forms in .NET[^] It passes values through properties - but properties are just syntactic sugar over getter and setter methods, so it works just as well for calling regular methods.


          Upcoming Scottish Developers events: * UK Security Evangelists On Tour (2nd November, Edinburgh) * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

          1 Reply Last reply
          0
          • C Christian Graus

            The main way to do this is to create delegates, so that your forms can call functions within each other. If you want something more quick and dirty, pass an instance of each form to the other form, and make the methods public. We need a FAQ, and this needs to be the first item on it. In fact, I thought we had one ?

            Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

            N Offline
            N Offline
            Nick Parker
            wrote on last edited by
            #5

            Christian Graus wrote:

            We need a FAQ, and this needs to be the first item on it. In fact, I thought we had one ?

            This has been a long....long...did I say long running feeling. Heath Stewart and I started one about 3 years ago. I don't think it ever came to fruition.

            - Nick Parker Microsoft MVP - Visual C#
            My Blog | My Articles

            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