Function calls across forms

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Shaun Pudwell

    #1

    Function calls across forms

    Hi, I am very new to C#, so this may seem to simple to be
    true. Anyway, the problem is this: I have my MainWindow
    class and an MDI child window and its associated class.
    The class MainWindow class has a function called
    DrawChart. My MDI child needs to make a call to DrawChart.

    Now I know I can say something along the lines of...

    MainWindow xxx = new MainWindow ();
    xxx.DrawChart ();

    The problem here is I have a counter in the MainWindow
    class, which gets reset every time a call to new
    MainWindow (); is made. How do I call this function from
    my MDI child window and keep the existing values inside
    the MainWindow class?

    Thanks in advance,
    Shaun Pudwell.
  • Greg Ewing [MVP]

    #2
    Re: Function calls across forms

    Shaun, you need to keep a reference to your original MainWindow object. You
    could do this by passing the object around or by creating a class level
    variable and storing the reference there. If you want to call MainWindow
    from your other form make sure to pass a reference to the other form
    pointing to your original MainWindow object.

    --
    Greg Ewing [MVP]
    IT support built exclusively for nonprofits. 25 years of managed IT, help desk, and cybersecurity - so your team can focus on your mission.


    "Shaun Pudwell" <shaun.pudwell@ tiscali.co.uk> wrote in message
    news:19fe01c379 4a$b61c61c0$a50 1280a@phx.gbl.. .[color=blue]
    > Hi, I am very new to C#, so this may seem to simple to be
    > true. Anyway, the problem is this: I have my MainWindow
    > class and an MDI child window and its associated class.
    > The class MainWindow class has a function called
    > DrawChart. My MDI child needs to make a call to DrawChart.
    >
    > Now I know I can say something along the lines of...
    >
    > MainWindow xxx = new MainWindow ();
    > xxx.DrawChart ();
    >
    > The problem here is I have a counter in the MainWindow
    > class, which gets reset every time a call to new
    > MainWindow (); is made. How do I call this function from
    > my MDI child window and keep the existing values inside
    > the MainWindow class?
    >
    > Thanks in advance,
    > Shaun Pudwell.[/color]


    Comment

    Working...