現在、私のコードは、このボタンをクリックするとファイルの選択ダイアログが開き、開くファイルを選択できるように設定されています。
private void button1_Click(object sender, System.EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
richTextBox1.LoadFile(openFileDialog1.FileName, RichTextBoxStreamType.RichText);
}
}
ただし、プログラムを変更して、プログラムが次のようにデフォルトファイルに出力されるようにしました。
public void CreateInventory(CreateInventory createinventory)
{
try
{
FileStream fileStream = new FileStream
("CreateInventory.bin", FileMode.Create,
FileAccess.Write);
IFormatter formatter = new BinaryFormatter();
formatter.Serialize(fileStream, createinventory);
fileStream.Close();
}
catch (ItemNotFoundException)
{
throw new ItemNotFoundException("Output not created - see logs");
}
}
ロードするファイルを選択するようにユーザーに求めるのではなく、そのファイルを直接ロードするようにボタンを切り替えるにはどうすればよいですか?