Click here to Skip to main content
15,896,444 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
hi I'm working on a project with C#,i work on forms with C#
i have a menu strip with a save option, in this form i need to save the work i have done , by clicking on the save option , i need it so save the changes i have done on the form with .cs extension next time when i open it i can start from i saved !!

the form contains drawings, text, and boxes with a save menu strip !!


this is my code :
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{

    SaveFileDialog dlg = new SaveFileDialog();

    dlg.Filter = "C Sharp Files (*.cs)|*.cs|Text Files (*.txt)|*.txt";
    dlg.AddExtension = true;
    dlg.DefaultExt = ".cs";

    if (dlg.ShowDialog() == DialogResult.OK)
    {
        System.IO.TextWriter w = new System.IO.StreamWriter(dlg.FileName.ToString());

        w.Write( output_richtextbx.Text );
 // but here i want to save the work i done to the form not the text ??
        w.Flush();
        w.Close();
    }

}


[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 1-May-11 2:10am
v2
Comments
Wonde Tadesse 1-May-11 9:12am    
Why don't you use an option from Visual Studio, File-> Save "FileName" as option. "FileName" will be your cs file.:)

1 solution

Sorry, but I may be a little confused: You want your application executable code to save changes you made in the Visual Studio designer?

Are you planning on shipping your entire source code and a copy of Visual Studio with each installation of your application?

Or are you confused about what you need to save where? To save changes you make in the designer, you just use the Visual Studio menu "File...Save All", which defaults to CTRL+SHIFT+S.


"no, my project is a windows form application, where i can draw , write ..
in this form i have a save button which will save the form and the changes i done.. so when the save button is clicked , it will save all i have done in a .cs file
and when i open the saved file, i want it o open the work i done in this form !!
I'm sorry for my weak english"



OK: Don't use the extension ".cs" - that implies it is a C# source file...

What you are asking for is too big for a quick answer! I suggest that you have a look at basic MSDN examples - Scribble[^] is probably a good one - and work around what they do. At least it will give you the idea, and the basics!

Sorry, but sometimes, there just is no substitute for reading! :laugh:
 
Share this answer
 
v2
Comments
nenalkhun 1-May-11 8:27am    
no, my project is a windows form application, where i can draw , write ..
in this form i have a save button which will save the form and the changes i done.. so when the save button is clicked , it will save all i have done in a .cs file

and when i open the saved file, i want it o open the work i done in this form !!

I'm sorry for my weak english
OriginalGriff 1-May-11 8:50am    
Answer updated
nenalkhun 1-May-11 8:58am    
I'm sorry but you didn't understand what i need !! :(

thanks anyway,
Sergey Alexandrovich Kryukov 1-May-11 18:19pm    
This is you who did not explain it.
Do you still have a question about it?

Griff gets my 5.
--SA
RaviRanjanKr 1-May-11 13:05pm    
Excellent Answer! My vote of 5 :)

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