Could you give me an example of how to do this?
Thanks
Sure.
From frmNewHoliday.cs -
public partial class frmNewHoliday : Form
-
{
-
//this would be the public member
-
public List<string> HolidayList;
-
//this would be the public method.
-
public List<string> GetHolidays()
-
{
-
return HolidayList;
-
}
-
//either way is ok, but you only need to do one of them.
-
-
public frmNewHoliday()
-
{
-
InitializeComponent();
-
}
-
-
private void frmNewHoliday_FormClosed(object sender, FormClosedEventArgs e)
-
{
-
this.DialogResult = DialogResult.OK;
-
}
-
}
-
From frmHoliday.cs, wherever you want to open the new holiday dialog -
List<string> newHolidays;
-
frmNewHoliday fnh = new frmNewHoliday();
-
DialogResult res = fnh.ShowDialog();
-
if (res = DialogResult.OK)
-
{
-
//heres two ways of doing it.
-
newHolidays = fnh.HolidayList;
-
//or, if you do it with a method...
-
newHolidays = fnh.GetHolidays();
-
}
-
Ok, what I did here is show you the bare bones of two methods. I chose a List<string> because I have no idea of what kind of object you need to pass. But if you need a list of strings, this is a good object. But you can do this with any kind of object. You can either use the public method that returns this type, or you can expose a public member of this type. Also, I used a DialogResult because you might want to cancel. Instead of on FormClosed, you could set the DialogResult when you push an ok button. Then in FormClosed, you can set the dialogResult to something else.
But if you said OK, then I showed you both ways to get to that list. I like exposing the public member. But if you are going to use a method to generate your list anyway, you might as well just make that public and get it's value once the form is closed. Either way works pretty much the same.