The best place for me might be the worst place for your requirements. As Bonnie says, show us more. Either show us the code you are using or show us what the problem is or at least describe the problem. And as Bonnie says, based on what we know, Form_Load would work.
We do not know your requiements but perhaps you need to do it before the form is shown. So one possibility is to create a separate form; let us call it Form2. the following is a simplified version of what it might be like.
public partial class Form2 : Form
{
public string Filename { get; set; }
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.ShowDialog();
Filename = ofd.FileName;
}
}
In the Program class (Program.cs) instead of:
Application.Run(new Form1());
You can have:
Form2 f2 = new Form2();
Application.Run(f2);
Form1 f1 = new Form1();
f1.Filename = f2.Filename;
Application.Run(f1);
Now that is probably not how you want to do it but we do not know the requirements, it might be what you want.