Click here to Skip to main content
15,914,162 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI i have a one text box. i am writing some text in text box and save this text as a word file.
if i write some text in a text box and doesn't save the text and then close the application at that time i want a message "The data has not been saved are you want to close the application"
how could i do this ?

Thanks in Advance ...
Posted

It is very simple it is only logic

1.
Count text length when he close the application, if the length>0
prompt appropriate message.

If you want to know the user modified in the textbox or not
Look it

Maintain status variable initially Zero

In the
TextChanged 

event set status=1 and prompt your message

Thanks
SP
 
Share this answer
 
v2
Comments
bbirajdar 3-Feb-12 7:53am    
Good answer. .My 4
Sridhar Patnayak 3-Feb-12 10:35am    
Thanks Bijdar
mayankshrivastava 4-Feb-12 4:01am    
Thanks for reply sridhar,
when i open my project text box is empty.suppose i wrote something in text box and exit the application without saving this text i want a message "The document has still not been saved. Are you sure you want to close the application?" ok
but when i wrote something in text box and save the text box data as a word file and close the application i want directly exit don't show any message.because i already save the data.
mayankshrivastava 4-Feb-12 4:06am    
for example- open any word file and write something then close it show's message and when u already save the file it doesn't show any message and directly close the application.
Declare a member variable as
C#
flagTextChanged=false;


OnTextChanged of TextBox
C#
flagTextChanged=true;


OnFormClose
C#
if(flagTextChanged)
MessageBox.Show("Not Saved Message");


Best of Luck
 
Share this answer
 
v2
Hi,

you can check it at the leave event of the textbox.

if you did not know leave event of textbox then read

[^]

Leave event of textbox is fire when you leave textbox.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900