Hello, try putting your save code inside of the Form Closing event. That event will fire when the user clicks the 'x' button, but before the richtextbox disposes. For example:
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (MessageBox.Show("Do you want to save your work?", "save your work", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
SaveFileDialog sfd = new SaveFileDialog();
if (sfd.ShowDialog() == DialogResult.OK)
cRTX.rtx.SaveFile(sfd.FileName);
}
}
I hope it helps.