#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    1
    Rep Power
    0

    Call methods from another form... and some more questions :)


    Hiho,

    I really have a stupid problem...

    Imagine... I have a form A.

    Within this form I call a method named setData();
    Form A:

    formB fb= new formB();
    fb.setData();
    this.Close();


    This setData() (in form B) looks like this:

    Public void setData()

    {
    this.variable="Why doesn't it work!?";
    this.label.Text="blablabla";
    }

    I mean it's soooooo easy... but why doesn't it work???

    The debugger runs trough that all without any complaints... But on the
    form...nothing changes!!!

    WHY???

    Btw... Why does a form sometimes close the whole application with
    this.Close() and another form doesn't???

    And sometime I can't close with "x"... it just hides and stays in the task
    manager... Mmhhhh...???

    Hope u can help me...

    James
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    109
    Rep Power
    12
    By default, your application has a main form, this is the form that is sent to the Application.Run() function when your application starts. When this form closes the application terminates unless another message loop (namely another form) is active.

    Now pressing the 'X' button calls the Form.Close() event, which frees all the resources created with the form and disposes it. Normally you don't want to do this; you just want to hide it. To do this simply override the Closing event:
    Code:
    private void Form_Closing(object sender, System.ComponentModel.CancelEventArgs e)
    {
    	e.Cancel = true;
    	this.Hide();
    }
    To close the application call Application.Exit() or close all your child and parent forms.

    As for why your code isn't working, I'd need to see more of it.

IMN logo majestic logo threadwatch logo seochat tools logo