hi

I'm using visual c# express.
I have 2 forms. form1 and SettingsForm.

In form 1 there is a buttons for opening the SettingsForm.

sending data from form1 to the settingsform is easy. I use a methode.
But that don't work vice versa. because I made the SettingsForm into form1.
how to send data from the settingsform to the form 1.

thanks for helping

Daniweb has a search function, I typed C# sending data between forms clicked the serch button and got lots of answers.
You will surely find what you are looking for.

Simple

Use Static Keyword

ex ://

//Form1

class form1
{
public static string mydata="";

public void buttonclick(sendr,e)
{
mydata="Hello";
}
}


//settingsform

MessageBox.Show(form1.mydata);

Simple

Use Static Keyword

ex ://

//Form1

class form1
{
public static string mydata="";

public void buttonclick(sendr,e)
{
mydata="Hello";
}
}


//settingsform

MessageBox.Show(form1.mydata);

I disagree with this method because the children form should not directly access it's parent.

One better way of passing information from the child to the parent is by having the parent create the child with referenced arguments.

//form 1
int info;
FormB myForm = new FormB(ref info);


//formB
int myInfo;
new FormB(ref int myReferencedInfo){
     myInfo = myReferencedInfo;
}

public void myMethod(){
    myInfo = 10;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.