متد آغاز کننده برنامه متد Main هست که میتونی پارامتر ورودی رو دریافت کنی.
static class Program
{
public static string FilePath { get; set; }
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
if (args != null && args.Length > 0)
{
Program.FilePath = args[0];
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(fals e);
Application.Run(new Form1());
}
}
در لودفرم هم میتونی متن رو بخونی و در کنترل مورد نظر نمایش بدی. از try...catch برای این استفاده میشه که ممکنه پارامتر آدرس اشتباهی باشه.
private void Form1_Load(object sender, EventArgs e)
{
if (Program.FilePath != null)
{
try
{
string content = File.ReadAllText(Program.FilePath);
textBox1.Text = content;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}