I have inherited some legacy code (in C# and python) which is a bit inconsistent. Sometimes pressing X saves the settings and closes the form, sometimes the X behaves like a cancel – does not save anything. Sometimes the user has to press ctrl-S to save then X to exit. This is described in the user manual but it is not something that is obvious.
I could put an extra label on each form indicating behaviour or just add save/cancel buttons but that would mean changing the layout of 50+ forms. Some of these forms cannot be lengthened anymore – they are the full screen height so I have to think of some other way of telling the user what the behaviour is or change the layout. It wold also mean that the entire user manual would have to be rewritten.
I was thinking of creating a tooltip so that when the user hovers over the X, a tooltip will flash up indicating the behaviour. Unfortunately, the tooltip requires the handle of the item. I’ve been trawling the net but I can’t find anything that tells me how to get the handle for the X or whether there is any special call for popping up tooltips when the mouse hovers over the X.
I’m just trying to do this in C# winforms. I will handle python if I can get it working in C#.
>Solution :
According to this answer: Change close button tooltip
It is effectively not possible to change this tooltip.
I would suggest an alternative.
On the forms which close without saving, add a new event for the FormClosing event which will ask the user if they first wish to save or not.
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (MessageBox.Show("Save changes", "Do you wish to save before closing?",MessageBoxButtons.YesNo, MessageBoxIcon.Question)
== DialogResult.Yes)
{
//Call method to save changes
}
}
If they answer yes, then you call the method to save the changes and then allow it to close.